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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
khanh_dam
Frequent Visitor

Year over year % change without date column

Hello friends,

I am new to Power BI and I was wondering how to get a YoY% for the below data. 

My data table:

year_montheventcountry
Y24M04AUS
Y24M04ACA
Y24M04BCA
Y24M04CCA
Y24M03DCA
Y24M03EUS
Y23M04FCA
Y23M04GCA
Y23M03HUS
Y23M03HCA
Y23M03IUS
Y23M03JCA

Results I need:

Year_monthevent_distinctcountevent_distinctcount_PYYoY
Y24M043250%
Y24M0323-33%

with a country slicer that can filter the results.

 

Thank you so much in advance!

Khanh

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @khanh_dam ,

 

Please modify the measure syntax as shown below:

event_distinctcount_PY = 
VAR _currentYear =
    VALUE ( MID ( SELECTEDVALUE ( 'Table'[year_month] ), 2, 2 ) )
VAR _currentMonth =
    VALUE ( MID ( SELECTEDVALUE ( 'Table'[year_month] ), 5, 2 ) )
var _Slicer_Country = VALUES('Table'[country])
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[event] ),
        FILTER (
            ALL ( 'Table' ),
            VALUE ( MID ( 'Table'[year_month], 2, 2 ) ) = _currentYear - 1
                && VALUE ( MID ( 'Table'[year_month], 5, 2 ) ) = _currentMonth
                &&'Table'[country] IN _Slicer_Country
        )
    )

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi @khanh_dam ,

 

Thanks for the reply from ryan_mayu  / Corey_M .

 

First, create a measure to calculate the distinct count for the current year.

event_distinctcount = DISTINCTCOUNT('Table'[event])

 

Then, create a measure to calculate the distinct count for the same period last year.

event_distinctcount_PY =
VAR _currentYear =
    VALUE ( MID ( SELECTEDVALUE ( 'Table'[year_month] ), 2, 2 ) )
VAR _currentMonth =
    VALUE ( MID ( SELECTEDVALUE ( 'Table'[year_month] ), 5, 2 ) )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[event] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            VALUE ( MID ( 'Table'[year_month], 2, 2 ) ) = _currentYear - 1
                && VALUE ( MID ( 'Table'[year_month], 5, 2 ) ) = _currentMonth
        )
    )

 

Finally, create a measure to calculate YOY.

YoY = 
DIVIDE(
    [event_distinctcount] - [event_distinctcount_PY],
    [event_distinctcount_PY],
    0
)

 

The final page result is shown below:

vhuijieymsft_0-1736837312675.png

 

The pbix file is attached.

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Hi Yang,

Thank you so much for your response! When I select just Y24 value(s) in the year_month slicer, the results table shows blank for the PY measure. How do we make the PY measure work without having to also select the PY values in the year_month slicer?

khanh_dam_0-1736869681354.png

Thank you!

 

Anonymous
Not applicable

Hi @khanh_dam ,

 

Please modify this measure as shown below, all else being equal:

event_distinctcount_PY =
VAR _currentYear =
    VALUE ( MID ( SELECTEDVALUE ( 'Table'[year_month] ), 2, 2 ) )
VAR _currentMonth =
    VALUE ( MID ( SELECTEDVALUE ( 'Table'[year_month] ), 5, 2 ) )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[event] ),
        FILTER (
            ALL ( 'Table' ),
            VALUE ( MID ( 'Table'[year_month], 2, 2 ) ) = _currentYear - 1
                && VALUE ( MID ( 'Table'[year_month], 5, 2 ) ) = _currentMonth
        )
    )

 

The final visual effect is shown below:

vhuijieymsft_1-1736927129011.png

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Hi @Anonymous ,

 

When I modified from ALLSELECTED to ALL then the Country slicer stops applying to the PY measure. Is there a way we can modify it so that this measure will be filtered by all other slicers but not the year_month slicer?

 

Thank you!

Anonymous
Not applicable

Hi @khanh_dam ,

 

Please modify the measure syntax as shown below:

event_distinctcount_PY = 
VAR _currentYear =
    VALUE ( MID ( SELECTEDVALUE ( 'Table'[year_month] ), 2, 2 ) )
VAR _currentMonth =
    VALUE ( MID ( SELECTEDVALUE ( 'Table'[year_month] ), 5, 2 ) )
var _Slicer_Country = VALUES('Table'[country])
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[event] ),
        FILTER (
            ALL ( 'Table' ),
            VALUE ( MID ( 'Table'[year_month], 2, 2 ) ) = _currentYear - 1
                && VALUE ( MID ( 'Table'[year_month], 5, 2 ) ) = _currentMonth
                &&'Table'[country] IN _Slicer_Country
        )
    )

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

khanh_dam
Frequent Visitor

@Corey_M , @ryan_mayu 

Thank you very much for your quick responses!

In the data I am working with, the year, quarter, and month numbers are not following the normal calendar. For example, 2024/04/01 is Y24M04 but 2023/04/01 might belong to Y23M03. 

So I was hoping for a solution when the year_month slicer is selected for one or more values, Y24M04 and Y24M06 for example, then eventcount measure would calculate for Y24M04 & Y24M06, and eventcount_PY would calculate for Y23M04 & Y23M06, and the YoY is the %difference of those two.

I was thinking of creating a lookup table with 2 columns, year_month, and year_month_PY like:

year_monthyear_month_PY
Y24M04Y23M04
Y24M05Y23M05
Y24M06Y23M06
Y24M07Y23M07
Y24M08Y23M08
Y24M09Y23M09

but I am not sure how to go from there or if that's the right direction.

Thank you!

ryan_mayu
Super User
Super User

@khanh_dam 

you need to create a date column and a date table

11.PNG

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Corey_M
Resolver II
Resolver II

this will be much easier with the creation of a separate calendar table (example calendar table) then you will need to either add a column to the calendar table to match your monthyear format or transform your monthyear format to match the calendar table so that they can form a proper relationship.

 

Once that is done it really is as simple as 

 

PriorYearEvents = Calculate(
  countrows(EventTable),
  ParallelPeriod(DateTable[Date],-1,year)
)

CurrentYearEvents = Countrows(EventTable)

YOYEvents = Divide((CurrentYearEvents - PriorYearEvents),PriorYearEvents)

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors