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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Soc3
Helper I
Helper I

YTD and YTD PY for multiple measures

I have created a number of measures for a variety of metrics and want to show them all in a matrix with YTD and YTD PY as two columns.

 

How can I convert the list of measures that I have into my desired format? I don't want to just switch values to rows because I want a more concise matrix.

 

Current matrix where all measures are values:

YTD 14334
YTD PY 1         3421
YTD 22564
YTD PY 21223
YTD 335234
YTD PY 33525

 

Desired matrix:

 YTDYTD PY
143343421
225641223
335234            3525

 

 

Thank you!!

 

1 ACCEPTED SOLUTION

Hi @Soc3 

Thank you for reaching out to the Microsoft Fabric Forum Community.

I reproduced your scenario in Power BI Desktop using sample data and validated the behavior.

To achieve the desired matrix layout (metrics on rows with YTD and YTD PY as columns), the recommended approach is to:

  • Create a disconnected Metrics table (e.g: 1, 2, 3).
  • Keep your existing individual measures (Metric 1, Metric 2, Metric 3).
  • Create dynamic YTD and YTD PY measures using SWITCH() that return the correct measure based on the selected metric.
  • Use the Metrics table in Rows, and place only YTD and YTD PY in Values.

I’ve attached a sample .pbix file where this is implemented step by step for your reference. You can open it and adapt the pattern directly to your model.


Thanks.

View solution in original post

9 REPLIES 9
Ashish_Mathur
Super User
Super User

Hi,

I am not sure how much i can help but i would like to try.  Share the download link of the PBI file with just 3 base measures and 3 YTD measures.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Kedar_Pande
Super User
Super User

@Soc3 

 

1. Create base measures (no YTD logic inside):


M1 = SUM('Table'[Metric1])
M2 = SUM('Table'[Metric2])
M3 = SUM('Table'[Metric3])
2. Create a measure field parameter
Modeling → New parameter → Fields → add M1, M2, M3.
Call it Metric Parameter.

3. Generic YTD + YTD PY using the parameter:


YTD Selected =
TOTALYTD ( SELECTEDMEASURE(), 'Date'[Date] )

YTD PY Selected =
CALCULATE (
[YTD Selected],
DATEADD ( 'Date'[Date], -1, YEAR )
)
4. Build the matrix:

Rows: Metric Parameter

Columns: YTD Selected, YTD PY Selected (as values)

 

If this answer helped, please click Kudos or Accept as Solution.
-Kedar
LinkedIn: https://www.linkedin.com/in/kedar-pande

Hi @Kedar_Pande 

 

Thanks for your response. I am trying your method and getting stuck on step 3. What do you mean "using the parameter"? The YTD formulas don't refer to the parameter just created and I get an error using this code "There is no measure reference in the current context to be applied as SELECTEDMEASURE.

 

Thanks!

 

Hi @Soc3 

Thank you for reaching out to the Microsoft Fabric Forum Community.

I reproduced your scenario in Power BI Desktop using sample data and validated the behavior.

To achieve the desired matrix layout (metrics on rows with YTD and YTD PY as columns), the recommended approach is to:

  • Create a disconnected Metrics table (e.g: 1, 2, 3).
  • Keep your existing individual measures (Metric 1, Metric 2, Metric 3).
  • Create dynamic YTD and YTD PY measures using SWITCH() that return the correct measure based on the selected metric.
  • Use the Metrics table in Rows, and place only YTD and YTD PY in Values.

I’ve attached a sample .pbix file where this is implemented step by step for your reference. You can open it and adapt the pattern directly to your model.


Thanks.

cengizhanarslan
Super User
Super User

Create a table like this (manually or via DATATABLE):
MetricID → 1, 2, 3 (or meaningful names).
Put MetricID on matrix rows.

 

Then create two generic measures using SWITCH():

 

One measure for YTD that returns [YTD 1], [YTD 2], [YTD 3] based on selected MetricID.
Another measure for YTD PY that does the same for [YTD PY 1], [YTD PY 2], [YTD PY 3].

 

Place these two measures as the only values in the matrix.
This gives you a compact matrix with YTD / YTD PY as columns.

 

YTD =
SWITCH (
    SELECTEDVALUE ( Metrics[MetricID] ),
    1, [YTD 1],
    2, [YTD 2],
    3, [YTD 3]
)
YTD PY =
SWITCH (
    SELECTEDVALUE ( Metrics[MetricID] ),
    1, [YTD PY 1],
    2, [YTD PY 2],
    3, [YTD PY 3]
)
_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.
danextian
Super User
Super User

Hi @Soc3 

 

If that is how your raw data really is, transform your data in the query editor so it looks like below:

danextian_0-1766033979924.png

danextian_1-1766034037775.png

Please see the sample M code below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WigxxUTBU0lEyMTY2UYrVgQgERILFjE2MDOFiRkABI1MzFEUgMUMjI2O4mDFIl6kRqlFQQVOl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"Value", Int64.Type}}),
    #"Inserted Text After Delimiter" = Table.AddColumn(#"Changed Type", "Text After Delimiter", each Text.AfterDelimiter([Category], " ", {0, RelativePosition.FromEnd}), type text),
    #"Extracted Text Before Delimiter" = Table.TransformColumns(#"Inserted Text After Delimiter", {{"Category", each Text.BeforeDelimiter(_, " ", {0, RelativePosition.FromEnd}), type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Extracted Text Before Delimiter",{{"Text After Delimiter", "Year"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Year", Int64.Type}})
in
    #"Changed Type1"

 

If you actually have different measures  for different columns, the approach is to use calculation groups to apply the same previous year logic to different measures.

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Irwan
Super User
Super User

hello @Soc3 

 

please check if this accomodate your need.

Irwan_0-1766013740284.png

since you want to have another matrix visual with different format, then you need to create another table because the value are different from your original data and also matrix Rows and Columns does not accept measure.

 

1. create a new table with following DAX.

Table 2 =
GENERATE(
    SUMMARIZE(
        ADDCOLUMNS(
            'Table',
            "Text",
            SUBSTITUTE(
                'Table'[Column1],
                RIGHT('Table'[Column1],2),
                ""
            )
        ),
        [Text]
    ),
    SUMMARIZE(
        SELECTCOLUMNS(
            'Table',
            "Number",
            RIGHT('Table'[Column1],1)
        ),
        [Number]
    )
)
Irwan_1-1766013907208.png

 

2. create a new measure that collect all your original measure.

Tranform Measure =
MAXX(
    FILTER(
        ALL('Table'),
        'Table'[Column1]=SELECTEDVALUE('Table 2'[Text])&" "&SELECTEDVALUE('Table 2'[Number])
    ),
    [Measure]
)
 
3. plot into new matrix.
Irwan_2-1766013976477.png

 

As mentioned by @lbendlin , this is "User Defined Functions in DAX", so you can have many other options.

 

Hope this will help where you can start.

Thank you.

lbendlin
Super User
Super User

The usual answer until recently would have been "Calculation Groups".  Nowadays the preferred answer is "User Defined Functions in DAX".  Have you considered that?

Hans-Georg_Puls
Super User
Super User

Hi @Soc3 , 

do I understand you right, that 1, 2 and 3 are placeholders for different metrics, but there will be more? Your goal is to have two columns for YTD and YTD PY and a row for every metric?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.