The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello,
I have a table with two value A & B. each them is group by data and segment.
I have to get the variation between the values A & B between the different Quarter and displayed only for the current date.
i made this DAX query but does not work correcly:
VariationTest =
VAR __mostRecentVisibleDate =
CALCULATE ( MAX ( Calendrier[Date] ); ALLSELECTED ( 'Calendrier' ) )
VAR __previousVisibleDate =
PREVIOUSQUARTER(Calendrier[Max Date])
VAR A = [sumamount]
VAR B =
CALCULATE (
[sumamount];
ALLSELECTED ( 'Calendrier' );
Calendrier[Date] = __previousVisibleDate
)
VAR __variancePercent =
DIVIDE ( B - A ; A )
RETURN
IF (
MAX ( Calendrier[Date] ) = __mostRecentVisibleDate;
__variancePercent
)
As PREVIOUSQUARTER does not take directly __mostRecentVisibleDate, I create Max Date column with
Max Date = MAX(Calendrier[Date])
Can someone help on this please.
Thank you in advance
Thank you very much, I will try that
Hi @Anonymous
Please try the following Dax:
VariationTest =
VAR __mostRecentVisibleDate =
MAXX(
ALLSELECTED('Calendrier'),
'Calendrier'[Date]
)
VAR __startOfQuarter =
STARTOFQUARTER(__mostRecentVisibleDate)
VAR __startOfPreviousQuarter =
STARTOFQUARTER(
EDATE(__mostRecentVisibleDate, -3)
)
VAR CurrentQuarterAmount =
CALCULATE(
[sumamount],
DATESBETWEEN(
'Calendrier'[Date],
__startOfQuarter,
__mostRecentVisibleDate
)
)
VAR PreviousQuarterAmount =
CALCULATE(
[sumamount],
DATESBETWEEN(
'Calendrier'[Date],
__startOfPreviousQuarter,
EDATE(__startOfQuarter, -1)
)
)
VAR __variancePercent =
DIVIDE(
PreviousQuarterAmount - CurrentQuarterAmount,
CurrentQuarterAmount
)
RETURN
IF(
MAX('Calendrier'[Date]) = __mostRecentVisibleDate,
__variancePercent,
BLANK()
)
Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
User | Count |
---|---|
27 | |
12 | |
8 | |
8 | |
5 |
User | Count |
---|---|
31 | |
15 | |
12 | |
7 | |
6 |