The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I have the following measure:
Previous Sales = IF(HASONEVALUE(DateDimension[Year]); CALCULATE(SUM(BI_Sales[Value]); DATEADD(DateDimension[DateKey]; -1; YEAR)); BLANK() )
And in my page, I have slicers for month and year, If user selects 2019 and 2018 the measure will work fine, my problem is when the user selects 2019 and 2017 or select just 2019 but 2 months, like January and May, note the months are not sequential.
Is there any way to verify if exists a contiguous selection to treat this case or correct this problem?
I have tried to use SAMEPERIODLASTYEAR.
Solved! Go to Solution.
Hi @gluizqueiroz,
I think you need to create a separate date table and then link your current table to the new date table.
Date table:
Date = CALENDAR(MIN('DateDimension'[DateKey]),MAX('DateDimension'[DateKey]))
And then you need to redefine this measure as shown below.
Measure:
Previous Sales = IF ( HASONEVALUE ( DateDimension[Year] ), CALCULATE ( SUM ( DateDimension[Value] ), FILTER ( ALL ( 'Date' ), YEAR ( 'Date'[Date] ) = YEAR ( MAX ( 'Date'[Date] ) ) - 1 && MONTH ( 'Date'[Date] ) = MONTH ( MAX ( 'Date'[Date] ) ) ) ), BLANK () )
Select [Date].Month from the data table as a slicer, the measure still works even if you select two months that are not sequential.
Best Regards,
Jack Chen
Hi @gluizqueiroz,
I think you need to create a separate date table and then link your current table to the new date table.
Date table:
Date = CALENDAR(MIN('DateDimension'[DateKey]),MAX('DateDimension'[DateKey]))
And then you need to redefine this measure as shown below.
Measure:
Previous Sales = IF ( HASONEVALUE ( DateDimension[Year] ), CALCULATE ( SUM ( DateDimension[Value] ), FILTER ( ALL ( 'Date' ), YEAR ( 'Date'[Date] ) = YEAR ( MAX ( 'Date'[Date] ) ) - 1 && MONTH ( 'Date'[Date] ) = MONTH ( MAX ( 'Date'[Date] ) ) ) ), BLANK () )
Select [Date].Month from the data table as a slicer, the measure still works even if you select two months that are not sequential.
Best Regards,
Jack Chen
Hey @Anonymous.
Your answer looks good, but I'm not have tried yet, when I try it, I came here to Accept or not your answer as correctly.
I not forget this post.
Thanks.