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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
MRIZ
Helper II
Helper II

Cards/KPIs showing Current Period vs Last Period on period (ThisD,ThisW,ThisM,ThisQ,ThisY) selection

Requirement:
Hi,
I am new to complex Power BI tasks. I have a task in which I have to show data for SELECTED PERIOD (This Year, This Month, This Quarter, This Week, This Day). Here, THIS means CURRENT. There should be no DATE SLICER. The report should show current vs previous data depending on TODAY's date. 
I have to show comparision between Current vs Previous periods using CARDS or KPIs which ever suits.
For ecample: 
If user selects THIS MONTH from PERIODS dropdown, the CARD or KPI should show CURRENT MTD REVENUE vs PREIOUS MTD REVENUE along with %age change. Also, if current Revenue is greater than last month revenue so far, color it GREEN or else color it RED. 
What i have done so far:

  1. Achieved making PERIOD selection . Make a custom table in Power bi like below. Will use this as a slicer. 

 

 

Periods = {
    ("This Year", NAMEOF('Date'[Year]),0,"This Year"),
    ("This Quarter", NAMEOF('Date'[Quarter]), 1,"This Quarter"),
    ("This Month", NAMEOF('Date'[Month]), 2,"This Month"),
    ("This Week", NAMEOF('Date'[WeekOfMonth]), 3,"This Week"),    
    ("This Day", NAMEOF('Date'[Day]), 4,"This Day")
}
​

 

 

  • Created Measure for Previous Values like below. I will pick Previous Value based on the Period Selection.

 

 

Selected Period Previous Revenue = 
VAR SelectedPeriod = SELECTEDVALUE('Dates'[Period],"This Day")
VAR DynamicValue = 
SWITCH(
   TRUE(),

     SelectedPeriod = "This Day", CALCULATE([Revenue], DATEADD('Date'[Date],-1, DAY)),
     SelectedPeriod = "This Week", CALCULATE([Revenue],DATEADD('Date'[Date],-7, DAY)),
     SelectedPeriod = "This Month", CALCULATE([Revenue],  DATEADD('Date'[Date],-1, MONTH)),
     SelectedPeriod = "This Quarter", CALCULATE([Revenue],DATEADD('Date'[Date],-1, QUARTER)),    
     SelectedPeriod = "This Year", CALCULATE([Revenue],DATEADD('Date'[Date],-1, YEAR)),
 
  BLANK()

)
 RETURN
 DynamicValue

​

 

 

  • Created Measure for Current Values like below. It will calculate Current Value based on the Period Selection.

 

 

Selected Period Current Revenue = 
VAR SelectedPeriod = SELECTEDVALUE('Dates'[Period],"This Day")
VAR DynamicValue = 
SWITCH(
   TRUE(),

     SelectedPeriod = "This Day", CALCULATE([Revenue], FORMAT ('Date'[Date],"yyyy-mm-dd") = FORMAT(TODAY(),"yyyy-mm-dd")),
     SelectedPeriod = "This Week", CALCULATE([Revenue],'Date'[WeekOfMonth] = WEEKNUM(TODAY()),'Date'[Month] = MONTH(TODAY()),'Date'[Quarter] = QUARTER(TODAY()),'Date'[Year] = YEAR(TODAY())),
     SelectedPeriod = "This Month", CALCULATE([Revenue],'Date'[Month] = MONTH(TODAY()) , 'Date'[Year] = YEAR(TODAY())),
    SelectedPeriod = "This Quarter", CALCULATE([Revenue],'Date'[Quarter] = QUARTER(TODAY()),'Date'[Year] = YEAR(TODAY())),    
  SelectedPeriod = "This Year", CALCULATE([Revenue],'Date'[Year] = YEAR(TODAY())),
  BLANK()

)
 RETURN
 DynamicValue​

 

 

  • PROBLEM: Added KPIs as achieving this with CARDS was difficult and lengthy. In this picture below, see the example of REVENUE KPI.  As of today in this month the REVENUE is  388.95 which is correct. But the LAST PERIOD is not what actually is in January,24. The REVENUE in January,24 was 2,387. Here you can notice one more thing, the MONTH it should be 2 somehow it shown 12. Same is the case with other KPIs too. 
    Revenue KPI.png

     

    Need help to achieve this case. Or share anyother better way to achieve this. 

Thanks, 

Rizwan. 

2 REPLIES 2
v-jiewu-msft
Community Support
Community Support

Hi @MRIZ ,

If I understand correctly, the issue is that you want to show data for selected period. Please try the following methods and check if they can solve your problem:

1.Ensure that the Date table in Power BI that it contains a continuous date range.

 

2.Review the logic within the DAX formula.

 

Selected Period Previous Revenue = 
VAR SelectedPeriod = SELECTEDVALUE('Dates'[Period], "This Day")
VAR StartDate = TODAY()
VAR EndDate = 
    SWITCH(
        SelectedPeriod,
        "This Day", StartDate,
        "This Week", StartDate - WEEKDAY(StartDate, 2) + 1,
        "This Month", DATE(YEAR(StartDate), MONTH(StartDate), 1),
        "This Quarter", DATE(YEAR(StartDate), QUARTER(StartDate) * 3 - 2, 1),
        "This Year", DATE(YEAR(StartDate), 1, 1),
        StartDate
    )
VAR PeriodLength = 
    SWITCH(
        SelectedPeriod,
        "This Day", 1,
        "This Week", 7,
        "This Month", DAY(EOMONTH(StartDate, -1)),
        "This Quarter", DAY(EOMONTH(StartDate, -MONTH(StartDate) MOD 3)),
        "This Year", DAY(EOMONTH(StartDate, -MONTH(StartDate) + 1)),
        1
    )
VAR PreviousPeriod = DATESINPERIOD('Date'[Date], EndDate, -PeriodLength, DAY)
RETURN
    CALCULATE([Revenue], PreviousPeriod)

 

 

3.Check that the measures are evaluated within the correct context.

 

Best Regards,

Wisdom Wu

Hi Brother, 

Thanks for taking time and responding to help me out. 
Yes the Date Table has continus Date Range. 
Unfotunaltely the DAX you shared did not work. See the output in the image below. I have selected "This Year" but you can see that the Previous Year is showing "2099" and showing "1.9K" revenue. Actual Revenue in 2023 was "8.5K" .Also attaching DAX again here which i used ( check the MOD method if i used it correctly as your MOD was giving error).

Selected Period Previous Revenue = 
VAR SelectedPeriod = SELECTEDVALUE('Dates'[Period],"This Day")
VAR StartDate = TODAY()
VAR EndDate = 
    SWITCH(
        SelectedPeriod,
        "This Day", StartDate,
        "This Week", StartDate - WEEKDAY(StartDAte,2) + 1,
        "This Month", DATE(YEAR(StartDate), MONTH(StartDate) * 3 - 2, 1),
        "This Quarter", DATE(YEAR(StartDate), QUARTER(StartDate) * 3 - 2, 1),
        "This Year", DATE(YEAR(StartDAte), 1, 1),
        StartDate
    )

VAR PeriodLength = 
SWITCH(
   SelectedPeriod,
        "This Day", 1,
        "This Week", 7,
        "This Month", DAY(EOMONTH(StartDate, -1)),
        "This Quarter", DAY(EOMONTH(StartDate, MOD (-MONTH(StartDate) , 3))),
        "This Year", DAY(EOMONTH(StartDate, -MONTH(StartDate) + 1)),
        1

)
VAR PreviousPeriod = DATESINPERIOD('Date'[Date], EndDate, -PeriodLength, DAY)
RETURN
    CALCULATE([Revenue], PreviousPeriod)


Year Revenue 2024-02-13 132340.png

 

Regards,

Rizwan. 
 

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Kudoed Authors