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.
I have a table from where I want to get the value from the previous available date for the specific Country-Indicator. The previous available date can be a day, month or quarter before.
I am available to get the inmediate previous date for the specified "Country-Indicator Key", and this is the formula I need support with twiking.
Previous Date =
CALCULATE(
MAX(Indicators[Date]),
ALLEXCEPT(Indicators,Indicators[Country-Indicator]),
Indicators[Date]<EARLIER(Indicators[Date])
)
What I get from the above DAX is a column that shows the previous available date for the specified "Country-Indicator":
Currently I have a work arround that creates a "Previous Key" and then looks for this value on the table, thus bringing the previous value, this can be either calculated column by column or in a single column:
Previous Value (not Fancy) =
VAR
PreviousDate =
CALCULATE(
MAX(Indicators[Date]),
ALLEXCEPT(Indicators,Indicators[Country-Indicator]),
Indicators[Date]<EARLIER(Indicators[Date])
)
VAR
PreviousKey =
FORMAT(PreviousDate,"yyyy-mm-dd")
&"-"&
Indicators[Country-Indicator]
RETURN
LOOKUPVALUE(
Indicators[Value_Rev],
Indicators[key],
PreviousKey
)
As mentioned I am looking for a way of modifying the "Previous Date" formulato bring the previous value instead of the previous date. I am just looking for a more elegant solution which I am confident it exists.
In the link below you can download the files.
https://1drv.ms/u/s!Aj1t-UWaJ-akgbRQhZIcveNiSLfYuQ?e=NE5q2Z
In advance thanks for your support.
@Oscar_Mtz_V
If the below screenshot is your expected result , please try the below code, you don't need to combine the Country and Indicator as a key, don't need to add an index column in Power Query. Just use DAX code.
PreviPreviousValue =
VAR _CurrentDate =
SELECTEDVALUE ( Sales[Date] )
VAR _PreviousDate =
CALCULATE (
MAX ( 'Sales'[Date] ),
ALLEXCEPT ( Sales, Sales[Country], Sales[Indicator] ),
KEEPFILTERS ( 'Sales'[Date] < _CurrentDate )
)
VAR _Result =
CALCULATE (
SUM ( Sales[Value_Rev] ),
'Sales'[Date] = _PreviousDate,
REMOVEFILTERS ( Sales[Date] )
)
RETURN
_Result
Did you solve this problem, if so how?
Hi @Oscar_Mtz_V
I think a good solution would be to create an Index column via Power QUery Editor mode (Add column pane -> Index column)
Then you will be able to do absolutely the same workaround as for date, but for Index column, like
Previous Value =
CALCULATE(
MAX(Indicators[IndexColumn]),
ALLEXCEPT(Indicators,Indicators[Country-Indicator]),
Indicators[IndexColumn]<EARLIER(Indicators[IndexColumn])
)
do not hesitate to give a kudo to useful posts and mark solutions as solution
Why do I keep getting a earlier/earliest refers to earlier row contex that does not exist error?? Please help
Did you use measure to create this expression? If so, you cannot use earlier/ealiest function
I am trying to do this in Power Pivot.
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 |
---|---|
46 | |
28 | |
22 | |
12 | |
8 |
User | Count |
---|---|
75 | |
52 | |
46 | |
15 | |
12 |