Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hello DAX gurus
I'm trying to create a filter in the DimDate table (my data table), which would put the flag as 1 when the data is in last completed week. This table sits on a SQL server, which I connect via Direct Query in Power BI. A week runs from Thursday to Wednesday. Last completed week would be 1 only when we go into Thursday of this week. See examples below.
In my date table, I was able to devise CurrentWeek, LastWeek, LastLastWeek filters. Also, I'm able to devise Last Thursday to This Wednesday. What I'm unable to devise is the Last Completed Week that matches the above logic.
Any help/directions you have for me would be awesome.
Cheers,
Harshal
Solved! Go to Solution.
Hi Harshal.
There are some limitations of applying DAX functions in the DirectQuery mode. Try out the following formula as a calculated column please.
BTW, the dates in your sample aren't continuous. I would suggest you use a complete date table instead.
LastWholeWeek = VAR currentWeek = WEEKNUM ( TODAY (), 1 ) VAR weekNum = IF ( [Weekday] IN { 5, 6, 7 }, WEEKNUM ( [Date], 1 ) + 1, WEEKNUM ( [Date] ) ) RETURN IF ( weekNum = currentWeek - 1, 1, BLANK () )
Best Regards,
Dale
Hi Harshal,
Did it solve your issue?
Best Regards,
Dale
Hi Harshal.
There are some limitations of applying DAX functions in the DirectQuery mode. Try out the following formula as a calculated column please.
BTW, the dates in your sample aren't continuous. I would suggest you use a complete date table instead.
LastWholeWeek = VAR currentWeek = WEEKNUM ( TODAY (), 1 ) VAR weekNum = IF ( [Weekday] IN { 5, 6, 7 }, WEEKNUM ( [Date], 1 ) + 1, WEEKNUM ( [Date] ) ) RETURN IF ( weekNum = currentWeek - 1, 1, BLANK () )
Best Regards,
Dale
Hi Harshal,
Please try out this measure. It works in my test Direct Query to SQL Server.
LastCustomWeek = VAR lastWed = CALCULATE ( MAX ( DateDimension[Date] ), FILTER ( ALL ( 'DateDimension' ), 'DateDimension'[Date] <= TODAY () && 'DateDimension'[Weekday] = 4 ) ) RETURN IF ( MIN ( 'DateDimension'[Date] ) <= lastWed && MIN ( 'DateDimension'[Date] ) >= lastWed - 6, 1, BLANK () )
Best Regards,
Dale
Thank you both for your replies, appreciate it.
Dale, the measure you created works like a charm. I had to adjust the criteria to make the switch day as Thursday (instead of Wednesday, as you had). Below is the updated measure. Is there a way that this calculation can be done in a Calculated Column instead? I need to add this new calculation as a page level filter. So, when the users log into the report, they see the week selected automatically, but they also have an option of changing the dates if need be.
LastCustomWeek =
VAR lastWed =
CALCULATE (
MAX ( 'Date'[DATE_] ),
FILTER (
ALL ( 'Date' ),
'Date'[DATE_] <= TODAY ()
&& 'Date'[Date Day] = 5
)
)
RETURN
IF (
MIN ( 'Date'[DATE_] ) < lastWed
&& MIN ( 'Date'[DATE_] )
>= lastWed - 7,
1,
BLANK ()
)
Thanks,
Harshal
@ChandeepChhabra: thanks, here is the link: https://www.dropbox.com/s/69nnw4rkk6x1s6o/DimDate.xlsx?dl=0
@harshaltannu : Can you also share a sample of the calculated column (output) you are expecting ?
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
99 | |
80 | |
64 | |
57 |
User | Count |
---|---|
145 | |
110 | |
91 | |
84 | |
66 |