Forum Discussion
filter problem in a calculate function - power bi desktop
- 10 years ago
jessicaf31 - I believe your problem is context with your jourdernierjour and/or DernierJour measure. In the context of your report, it shows 3, but in the row context when your sumjoursemaine measure is calculating, DernierJour always equals the MAX of that row and thus jourdernierjour always equals the joursemaine column.
Try changing your DernierJour measure to this:
DernierJour = MAXX(ALL(Transactions),Transactions[Date])
What this does is force DernierJour to always evaluate in the context of all of the rows, which means that DerierJour will always be the MAX date within the table, which means that jourdernierjour will always be the value of the weekday of the MAX date in the table, which *should* mean that you get the right answer in your report.
jessicaf31 - So, I am not super familiar with your data model, but here if you can replicate this, it should get you there.
Sum of Last Value = VAR LastDayofWeek = AVERAGEX(FILTER(ALL(dates),[date]=MAX([Date])),[DayofWeek]) RETURN ( CALCULATE(SUM([Value]),FILTER(ALL(dates),[DayofWeek]=LastDayofWeek)))
So, first, figure out the MAX of the date and what the DayofWeek translates to. Assuming that all Wednesdays are "3", then taking the average will return 3 no matter how many 3's there are. My table has a Date column and a DayofWeek column calculated from the date using WEEKDAY().
Use that value to filter the rows in the table and sum the appropriate column ([Value])
Greg_Deckler Thanks again for taking time to answer and help me.
I have done the same but it is still not working.
I will describe all the steps I have done and maybe you will detect my mistake :smileyvery-happy:
1) I've created a measure DernierJour = MAX(Transactions[Date]) (DernierJour means LastDay in french :smileyhappy: )
-> it returns Wednesday 24 February 2016
2) I've created a measure jourdernierjour = WEEKDAY([DernierJour];2) (for knowing the day of the LastDay)
-> it returns 3
3) I've created a column joursemaine = WEEKDAY(Transactions[Date];2) (for knowing each weekday for each date)
3) Now I want to know the total of amount only for the days which are wednesdays (LastDay) so I've created the measure :
sumjoursemaine = CALCULATE(SUM(Transactions[amount]);FILTER(ALL(Transactions);Transactions[joursemaine]=[jourdernierjour]))
-> it returns the total of all Transactions[amount] (6,8M) without filtering on the last day (I want 886K)
Whereas when I enter this formula :
sumjoursemaine = CALCULATE(SUM(Transactions[amount]);FILTER(ALL(Transactions);Transactions[joursemaine]=3))
It works...:smileyfrustrated:
Thanks again !!
- Greg_Deckler10 years agoCommunity Champion
jessicaf31 - I believe your problem is context with your jourdernierjour and/or DernierJour measure. In the context of your report, it shows 3, but in the row context when your sumjoursemaine measure is calculating, DernierJour always equals the MAX of that row and thus jourdernierjour always equals the joursemaine column.
Try changing your DernierJour measure to this:
DernierJour = MAXX(ALL(Transactions),Transactions[Date])
What this does is force DernierJour to always evaluate in the context of all of the rows, which means that DerierJour will always be the MAX date within the table, which means that jourdernierjour will always be the value of the weekday of the MAX date in the table, which *should* mean that you get the right answer in your report.
- jessicaf3110 years agoAdvocate I
Greg_Deckler Thanks a lot it worked !!! :smileyvery-happy:
- Mykhael10 years agoKudo Kingpin
OK, It is very hard to help you when I dont have to much information about your data, BUT, using the values you showed us I found a way to help you with your problem, I can send you the Power BI file if you want just give me your email. Let me know if this helps.
Best
Miguel Myers
- jessicaf3110 years agoAdvocate I
Mykhael Thanks a lot for all these screenshots !! I will try to do the same :)
The measure suggested by Greg_Deckler worked too :smileywink:
Thanks for your time !! :smileyhappy:
Jessica
- Mykhael10 years agoKudo Kingpin
Hello Jessicaf31
Can you send me the file? I want to see it and check where the problem comes from? In that way I will help you ASAP on that problem you have.
Best
Mykhael