Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Anonymous
Not applicable

Week Filter

Hi

Does anyone know why this DAX doesnt work...

 
Prior Week = CALCULATE([UAP's],FactNELWeekly[Previous Week No.])
 
UAPs = count distict measure, works fine.
Previous Week No. is a number column, in this case "8"
 
I have a weekly aggregated table, so i dont have a date column, just weekkey and week number, which is fine in this case, although not the usual way i model...actaully i count convert the below into a date format and wasnt sure if i need to.
 
All im lookiing to do is take this week's UAP figure, last weeks UAP figure, and minus them to get the WoW. But my DAX above doesnt seem to like filtering on a week number (created a column for previous week which was simply Week-1)
 

Example of my data table below:

 

Capture.PNG
Any sugguestions would be much appreciated please. 
 
Thanking you in advance
Ben
1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

So, the way that I would do this in a measure would be something along the lines of:

 

Prior Week =
  VAR __PreviousWeek = MAX('FactNELWeekly'[Previous Week No.])
RETURN
  CALCULATE([UAP's],FILTER('FactNELWeekly'[Week] = __PreviousWeek)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Solved:

 

UAPs Prior Week = VAR __PreviousWeek = MAX('FactNELWeekly'[Previous Week No.])
return
CALCULATE([UAP's],FactNELWeekly[Week] = __PreviousWeek)
 
Thanks to all who contributed!
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

Based on @Greg_Deckler 's suggestion,the measure needs to be corrected as below:

 

 

Prior Week =
  VAR __PreviousWeek = MAX('FactNELWeekly'[Previous Week No.])
RETURN
  CALCULATE([UAP's],FILTER('FactNELWeekly','FactNELWeekly'[Week] = __PreviousWeek)
 WoW=[UPA's]-_PreviousWeek

 

 

Best Regards,
Kelly
 
Did I answer your question? Mark my post as a solution!
Anonymous
Not applicable

Hi Kelly @v-kelly-msft 

 

I have an additional question on this topic, everything works with the DAX above, so thanks againn for that. But im noticing there's a week 0 appearing, and actually I've replicated this for a monthly report and again, im getting a 0 month. Is there a way to take care of this scenario within the same Dax formula? I figured it would be linked to this formula, hence why im posting here.

 

I'm googling this now acutally, but thought i'd try my luck here at the same time :).

 

Thanks

Ben

Anonymous
Not applicable

thank you so much! 

 

this did the trick nicely, really appreciated!

Thanks @v-kelly-msft ! That's what happens when I don't actually test my DAX, I mess up some syntax!


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

So, the way that I would do this in a measure would be something along the lines of:

 

Prior Week =
  VAR __PreviousWeek = MAX('FactNELWeekly'[Previous Week No.])
RETURN
  CALCULATE([UAP's],FILTER('FactNELWeekly'[Week] = __PreviousWeek)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thank you so much, this worked!

 

Much appreciated.

Anonymous
Not applicable

HI,

 

It could be something like this (if it's a calculated column):


var previousWeek = FactNELWeekly[Previoud Week No.]

return
CALCULATE([UAP's],FactNELWeekly[Week No.] = previousWeek)

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.