The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hi, I'm looking to create a DAX measure to solve the same problem as this:
The solution to this was creating a calculated column, however I am limited to using only DAX measures in my current model.
Basically, given a list of companies and order dates, I need a field that tells me how long ago the last order was for every row, like:
Thanks in advance for the help!
Hi @Anonymous
Try this measure:
Measure =
VAR _top2 =
TOPN(
2,
FILTER(
ALL( 'Table' ),
[Company] = SELECTEDVALUE( 'Table'[Company] )
&& [Order Date] < SELECTEDVALUE( 'Table'[Order Date] )
),
[Order Date], DESC
)
VAR _pdate =
MAXX( _top2, [Order Date] )
RETURN
DATEDIFF( _pdate, SELECTEDVALUE( 'Table'[Order Date] ), DAY )
And the pbix file I put in the attachment you can reference.
Best Regards
Community Support Team _ chenwu zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Thanks for the reply! PBI won't let me use my company column in this measure. Both the company column and the order date column are just regular columns in my model, not measures, which I believe is the problem. Is there a workaround to this that you know of?
User | Count |
---|---|
86 | |
84 | |
36 | |
34 | |
34 |
User | Count |
---|---|
93 | |
79 | |
66 | |
55 | |
52 |