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
antoniosantos
Frequent Visitor

How to display months, comparing current against previous period in a bar visual with a date slicer?

Hello,

The measure calculates sliced period's values, but I'd need to compare it with previous period. I've come this far, but since the slicer says `this month`, then it won't show the past months, given this measure.

 

TotalVpago_pcveicul_Comparison = 
VAR SelectedFilter =
    FILTER(
        pclanc,
        pclanc[CODCONTA] IN 
        CALCULATETABLE(
            VALUES(pcconta[CODCONTA]),
            pcconta[GRUPOCONTA] IN {501, 510},
            NOT(ISBLANK(pcconta[CODCONTAMASTER])),
            pcconta[CODCONTAMASTER] IN 
            CALCULATETABLE(
                VALUES(pcveicul[CODVEICULO]),
                pcveicul[CODLOCALIZACAO] = 1
            )
        )
    )

VAR SelectedPeriodVPAGO = 
    CALCULATE(
        SUM(pclanc[VPAGO]),
        SelectedFilter
    )
    
VAR PreviousPeriodVPAGO = 
    IF(
        HASONEVALUE(pclanc[Date]),   // Check if there's a single date value in the drill-through filter
        CALCULATE(
            SUM(pclanc[VPAGO]),
            SAMEPERIODLASTYEAR(pclanc[Date]),
            SelectedFilter
        ),
        BLANK()  // Return blank when there's no single date value (i.e., drill-through filter removed)
    )
    
RETURN
    SelectedPeriodVPAGO + PreviousPeriodVPAGO

 

 

This is what it shows, but I'd like it to show previous months and their comparisons from last year's months.

antoniosantos_0-1690668423888.png

Appreciate any help!

 

1 REPLY 1
TomMartens
Super User
Super User

Hey @antoniosantos,

 

i recommend reading this article: https://www.daxpatterns.com/time-patterns/

The article contains almost everything one needs to know about date/time related calculations. It also explains why these type of calculations require a dedicated data table (the first step to a star schema).

Hopefully, this gets you started.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

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.