Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Need help in DAX to calculate Previous year data

Hi Team,  @tamerj1

Thanks for helping in the below mentioned question.

Solved: Re: Need Help with DAX Command - Microsoft Power BI Community

below is the formula which is working fine .
CYCQCW-Win Rev =
VAR CurrentFCST = MAX ( 'Trend'[FCST] )
VAR CurrentWeek = MAX ( 'Trend'[WEEK_NUM] )
VAR CurrentStage = MAX ( 'Trend'[SS_No])
VAR CurrentValue = MAX ( 'Trend'[REV$M] )
VAR MaxWeek = CALCULATE ( MAX ( 'Trend'[WEEK_NUM] ), ALLEXCEPT ( 'Trend', 'Trend'[FCST] ) )
RETURN
IF (
CurrentFCST = "CQ" && CurrentWeek = MaxWeek && CurrentStage IN { "07", "08" },
CurrentValue,
0
);

Requirement : To calulate previous year CQ data so that we can create a yty .

data set :

FCSTWEEKSTAGEREVENUE
CQ407200
NQ809100
CQ40850
PYCQ40730
PYCQ100860
PYCQ40890

 

So my expectation is i have to filter fcst = pycq and stage = 07 , 08  and max of week where fcst = cq in this case 4 and update the vlaue in new column rest all will be 0 , in above case row 4 will give me a value of 30 and row  will give me a value 90 , rest all will be 0 . 
reason : I have to calculate yty,  in order to calculate yty i have to get previous year same qtr same week data so that we are comparing evenly . you can use the above formula to modify.

Thanks & Regrards
Shiv

 

1 ACCEPTED SOLUTION

Hi @Anonymous 

you are right

code is updated in the previous comment 

View solution in original post

3 REPLIES 3
tamerj1
Super User
Super User

Hi @Anonymous 

if you are looking for a measure the

 

CYCQCW-Win Rev =
VAR CurrentFCST =
    MAX ( 'Trend'[FCST] )
VAR CurrentWeek =
    MAX ( 'Trend'[WEEK_NUM] )
VAR CurrentStage =
    MAX ( 'Trend'[SS_No] )
VAR CurrentValue =
    MAX ( 'Trend'[REV$M] )
VAR MaxWeek =
    CALCULATE ( MAX ( 'Trend'[WEEK_NUM] ), 'Trend'[FCST] = "CQ" )
RETURN
    IF (
        CurrentFCST = "PYCQ"
            && CurrentWeek = MaxWeek
            && CurrentStage IN { "07", "08" },
        CurrentValue,
        0
    )

 

For column

 

CYCQCW-Win Rev =
VAR CurrentFCST =
    'Trend'[FCST]
VAR CurrentWeek =
    'Trend'[WEEK_NUM]
VAR CurrentStage =
    'Trend'[SS_No]
VAR CurrentValue =
    'Trend'[REV$M]
VAR MaxWeek =
    CALCULATE ( MAX ( 'Trend'[WEEK_NUM] ), 'Trend'[FCST] = "CQ" )
RETURN
    IF (
        CurrentFCST = "PYCQ"
            && CurrentWeek = MaxWeek
            && CurrentStage IN { "07", "08" },
        CurrentValue,
        0
    )

 

Anonymous
Not applicable

Hi @tamerj1 ,

Thanks for replying !!

QQ : which week number the Current week = maxweek return based on the above dataset if it is 4 then it is fine , if it is 10 then in that case i am looking for week number as 4. As I want to compare Current week of current year vs the same week of previous year .
Thanks & Regards

Shiv

Hi @Anonymous 

you are right

code is updated in the previous comment 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.