Forum Discussion

Ray_Minds's avatar
Ray_Minds
Icon for Solution Supplier rankSolution Supplier
2 years ago

Calculate and Show Last week Data Using DAX in Power BI

https://www.rayminds.com/post/calculate-and-show-last-week-data-using-dax-in-power-bi 

We will explore how to display last week's data.

We are going to utilize DAX functions to create the Calculated Date Dimension Table and we will be displaying the visualization using the sample data to illustrate the number of tickets, issues, and resolved cases from the past week. Below are the steps for the same: To calculate last week Data

Steps:-
1. Create Date Dimension :- We will use CALENDAR Function for get list of dates which we defined in the Range and along with we are using the NOW() Function in the Range which basically show the Today’s date (Current Date)  Dax Syntax :- Date DImension Table = CALENDAR(DATE(2024,01,01),NOW())

2. Get week number :- WEEKNUM Function show the week number in the listed Year

       Dax Syntax :-WeekNumber = WEEKNUM('Date DImension Table'[Date])
 

3 .Create last week's flag as 0 and 1

    Dax Syntax :-Last Week Flag =VAR Preweek = CALCULATE(MAX('Date DImension Table'[Week])-1 , ALL('Date DImension Table'))
    RETURN
    IF('Date DImension Table'[Week]=Preweek , 1,0)


4.  We will use the Date column to make an active relationship between Date Dimension Table and sample data tables .

5. We can now present last week's issues based on the measures specified, using sample data to create the visualization.

6. We will use the Last week flag column = 1 as a filter on the visual below, which will help us to fetch the last week data.

If you need more help please go to below link 

https://www.rayminds.com/post/calculate-and-show-last-week-data-using-dax-in-power-bi 

 

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, Ray_Minds 

    This is a great blog, do you have any questions about Calculate and Show Last Week Data Using DAX in Power BI, you can describe your needs in detail.

    Best Regards,
    Yang
    Community Support Team