最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

powerbi - MTD LY and FULL MONTH based on month slicer selection - Stack Overflow

programmeradmin4浏览0评论

I have a date slicer Based on a date selection I'd like to see Sales for this year (TY) and last year (LY)

If current month is selected on a slicer then it should show MTD sales TY and MTD LY If previous months are selected then it should give me full month TY and LY actual sales

  1. Is there a way I can code DAX so that users can interact with slicers and see respective sales?
  2. Is there a way to save current month (February 2025) as selected by default in date slicer?

I tried with SAMEPERIODLASTYEAR but it gives me full month for Feb'24 - I just need MTD for current month. Current month = my last sales date in my fact table (Feb'13 2025 in this case)

I have a date slicer Based on a date selection I'd like to see Sales for this year (TY) and last year (LY)

If current month is selected on a slicer then it should show MTD sales TY and MTD LY If previous months are selected then it should give me full month TY and LY actual sales

  1. Is there a way I can code DAX so that users can interact with slicers and see respective sales?
  2. Is there a way to save current month (February 2025) as selected by default in date slicer?

I tried with SAMEPERIODLASTYEAR but it gives me full month for Feb'24 - I just need MTD for current month. Current month = my last sales date in my fact table (Feb'13 2025 in this case)

Share Improve this question asked Feb 15 at 3:45 B TB T 291 silver badge5 bronze badges 1
  • could you pls provide some sample data? do you have a date table? – Ryan Commented Feb 17 at 0:22
Add a comment  | 

1 Answer 1

Reset to default 0

Try capturing the max date and then using that within an outer calculate:

Your Measure = 
  var maxD = MAX(YourFactTable[Date])
  var isCurMonth = (EOMONTH(MAX(YourDateTable[Date]), 0) = EOMONTH(TODAY(), 0))

  var fullMonth = CALCULATE([Your TY Measure], DATEADD(YourDateTable[FMStartDate], -1, YEAR))

  var partialMonth = 
    CALCULATE(
      CALCULATE([Your TY Measure], DATEADD(YourDateTable[FMStartDate], -1, YEAR)), 
      YourDateTable[Date] <= maxD
    )

  var result = IF( isCurMonth, partialMonth, fullMonth)

  return result 
发布评论

评论列表(0)

  1. 暂无评论