Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi everyone. Still trying to understand the basics of CALCULATE and filter context.
This problem is really hard for me to solve, so looking forward to your input/solutions.
My objective is to build tables, that only include latest data for each category;
With no filters, I wan't the latest row for each category:
And if filtered on District=z, I want:
Here is a workbook with the data/tables - thanks in advance!
What I have
My current attempt is to add a measure, and then use it as visual filter:
IsLatest = MAXX(
'fact',
VAR Category = 'fact'[category] RETURN
VAR Latest = CALCULATE(MAX('fact'[date]), ALLSELECTED(),'fact'[category] == Category) RETURN
IF('fact'[date] == Latest, 1, 0)
)
But it does not return the correct value (here filtered on distrcit=z);
Solved! Go to Solution.
@alexbjorlig
You have built the correct logic but you don't need to iterate over the fact table.
I modified your measure:
Latest =
VAR __category = MAX('fact'[category])
VAR __maxdate = CALCULATE( MAX('fact'[date] ) , ALLSELECTED('fact' ) , 'fact'[category] = __category )
return
INT ( max('fact'[date]) = __maxdate )
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
@alexbjorlig
You have built the correct logic but you don't need to iterate over the fact table.
I modified your measure:
Latest =
VAR __category = MAX('fact'[category])
VAR __maxdate = CALCULATE( MAX('fact'[date] ) , ALLSELECTED('fact' ) , 'fact'[category] = __category )
return
INT ( max('fact'[date]) = __maxdate )
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Thanks man - amazing when the solution turn out to be more simple than expected 🚀
COuld you please provide more information. Also along with your PBI file.
More information - what whould you like to know more?
As described the post, the file is here.
Okay I will check and get back to you.
Hi @KasunManchanaya - thanks for giving it a try, but does not seem to work.
I don't think it's possible to use a calculated column, because the value is only calculated once, and does not dynamically adopt.
If there is a filter requirement CC will not help you. then you have to do it in the measure itself. I will give it a try and let you know.
Mark and solved if this solve your query.
User | Count |
---|---|
25 | |
12 | |
8 | |
7 | |
7 |
User | Count |
---|---|
25 | |
12 | |
11 | |
10 | |
6 |