Forum Discussion
Anonymous
2 years agoNot applicable
YoY Comparison with Variable Logic in Power BI - Need Help with DAX Measure
Hi Community, I'm working on a Power BI report and have run into a problem with my Year-over-Year (YoY) comparisons. Here's the scenario: I have a table called "Market Revenue" with the following r...
Anonymous
2 years agoNot applicable
Hi, Anonymous
Based on your description, your DAX expression might look something like this:
P13M Market MTD YoY % Revised =
VAR ReferenceDate = MAX ( DateTable[Date] )
VAR ReferenceYear = YEAR ( ReferenceDate )
VAR LogicToUse = SWITCH (
TRUE (),
ReferenceYear = 2024, "new",
ReferenceYear = 2023, "old",
"old"
)
VAR ReferenceDatePY = DATE ( YEAR ( ReferenceDate ) - 1, MONTH ( ReferenceDate ), DAY ( ReferenceDate ) )
VAR PreviousDates = DATESINPERIOD ( DateTable[Date], ReferenceDate, -13, MONTH )
VAR PreviousDatesPY = DATESINPERIOD ( DateTable[Date], ReferenceDatePY, -13, MONTH )
VAR P13M_Market_MTD_PY = CALCULATE (
SUM ( 'Market Revenue'[Revenue] ),
FILTER (
'Market Revenue',
'Market Revenue'[Logic] = LogicToUse
),
SAMEPERIODLASTYEAR ( DateTable[Date] ),
REMOVEFILTERS ( DateTable ),
KEEPFILTERS ( PreviousDatesPY )
)
VAR P13M_Market_MTD_YoY = DIVIDE ( [P13M Market MTD], P13M_Market_MTD_PY ) - 1
VAR P13M_YoY_CALC = CALCULATE (
P13M_Market_MTD_YoY,
REMOVEFILTERS ( DateTable ),
KEEPFILTERS ( PreviousDates )
)
VAR Result = IF ( P13M_YoY_CALC = -1, BLANK (), P13M_YoY_CALC )
RETURN
Result
Are you able to provide some sample data? Please don't include any sensitive data.
How to Get Your Question Answered Quickly
If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .
Best Regards
Jianpeng Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous2 years agoNot applicable
Thank you Anonymous! Of course I can provide you with some sample data. Your help is very much appreciated!! https://www.dropbox.com/scl/fi/6fo4qu0bmxakc76assv62/Sample.xlsx?rlkey=3v71ecx4v899m4emr4pex2l2i&st=rkhj603x&dl=0