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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
solowolf
Frequent Visitor

Need Assistance with Previous Week formula and the result to display on a card visualization

Hello,

 

I am looking for some guidance on how to display a previous week's total on a card visualization. The functions I am using work very well on a table but not on a card. Any help is greatly appreciated.

<Apps PW =
VAR CurrentWeek = SELECTEDVALUE(DimDate[Week of Year])
Var CurrentYear = SELECTEDVALUE(DimDate[YearNumber])
Var MaxWeekNumber = CALCULATE(MAX(DimDate[Week of Year]), ALL(DimDate))


RETURN
SUMX(FILTER(ALL(DimDate),
    IF(CurrentWeek = 1 ,
        DimDate[Week of Year] = MaxWeekNumber && DimDate[Year] = CurrentYear - 1,
            DimDate[Week of Year] = CurrentWeek -1 && DimDate[Year] = CurrentYear)),
            [Total Applications])>

 

Regards, Patricio

 

 

 

 

 

2 ACCEPTED SOLUTIONS
dax
Community Support
Community Support

Hi @solowolf , 

You could try to use below measure to see whether it work or not.

Measure = CALCULATE(SUM('Table'[amount]), FILTER(ALLEXCEPT('Table','Table'[name]), YEAR('Table'[date])=SELECTEDVALUE('Table 2'[year])  && WEEKNUM('Table'[date])=MAX('Table 2'[week])-1))

You could refer to my sample for details.

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

solowolf
Frequent Visitor

Hello,

 

 

Thank you so much for your help. I ended up doing a poor man's fix to this. In my date table from the source (SQL Query) I flagged the following using columns before bringing them into my model:

 

1. prior day =1

2. prior week =1

3. prior month = 1

4. prior year =1

 

...and I did the same for current, day, week, month and year.

 

 

This way I was able to write a simple DAX formula like such:

 

 

Total Last Month = CALCULATE([Total Applications], DimDate[PriorMonth] = 1)
 
 
For example, if March is your current month, then all of the dates for March will be flagged with a "1" and the previous month dates (February) will be flagged as 1.
 
I hope this helps someone out there that had the same issue as I did.
 
 
Regards,
Solowolf

View solution in original post

2 REPLIES 2
dax
Community Support
Community Support

Hi @solowolf , 

You could try to use below measure to see whether it work or not.

Measure = CALCULATE(SUM('Table'[amount]), FILTER(ALLEXCEPT('Table','Table'[name]), YEAR('Table'[date])=SELECTEDVALUE('Table 2'[year])  && WEEKNUM('Table'[date])=MAX('Table 2'[week])-1))

You could refer to my sample for details.

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

solowolf
Frequent Visitor

Hello,

 

 

Thank you so much for your help. I ended up doing a poor man's fix to this. In my date table from the source (SQL Query) I flagged the following using columns before bringing them into my model:

 

1. prior day =1

2. prior week =1

3. prior month = 1

4. prior year =1

 

...and I did the same for current, day, week, month and year.

 

 

This way I was able to write a simple DAX formula like such:

 

 

Total Last Month = CALCULATE([Total Applications], DimDate[PriorMonth] = 1)
 
 
For example, if March is your current month, then all of the dates for March will be flagged with a "1" and the previous month dates (February) will be flagged as 1.
 
I hope this helps someone out there that had the same issue as I did.
 
 
Regards,
Solowolf

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.