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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Krexx
Helper I
Helper I

Create Column Header above Measures in Matrix or delete empty columns

Hello together, i will try it simple 🙂

Krexx_0-1611574856155.png

I would like to achieve this 

Test2.png

Krexx_0-1611574002726.png

So now when i am using following code i am losing the measure under the headername "Month" & "YTD", so i cant rename them: 

 

__H_R_Monat_Test =
VAR Spalte = SELECTEDVALUE(Spalten2[Spalte])
Return
SWITCH(TRUE(),Spalte="Month", CALCULATE([H_R_Month]),
Spalte="YTD", CALCULATE([H_R_YTD]))

 

View:

Krexx_2-1611574197351.png


When i am using for each measure an own calculation like this for month and YTD: 
Month: 

 

__H_R_Monat_Test =
VAR Spalte = SELECTEDVALUE(Spalten2[Spalte])
Return
SWITCH(TRUE(),Spalte="Month", CALCULATE([H_R_Month]))

 

YTD:

 

__H_R_Monat_Test =
VAR Spalte = SELECTEDVALUE(Spalten2[Spalte])
Return
SWITCH(TRUE(),Spalte="Month", CALCULATE([H_R_Month]))

 

I am getting the following result:
Test.png

 

1 ACCEPTED SOLUTION

Hi @Krexx 

 

Instead of using a variable use the syntax within the switch measure:

SWITCH(SELECTEDVALUE(Spalten[ID]),
1, CALCULATE([H_R_Monat]),
2, CALCULATE([H_A_Monat]),
3, CALCULATE([H_Ist_Gesch_M]),
4, CALCULATE([H_P_Monat]),
5, CALCULATE([H_Abw_Monat]),
6, CALCULATE([H_in%_Monat]),
10, CALCULATE([H_R_YTD]),
11, CALCULATE([H_A_YTD]),
12, CALCULATE([H_Ist_Gesch_YTD]),
13, CALCULATE([H_P_YTD]),
14, CALCULATE([H_Abw_YTD]),
15, CALCULATE([H_in%_YTD]),
19, CALCULATE([H_P_Year]),
20, CALCULATE([H_P_Monat])
)

 

 

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

8 REPLIES 8
MFelix
Super User
Super User

Hi @Krexx 

 

You need to place both measure in the same switch function:

_H_R_Monat_Test =
VAR Spalte = SELECTEDVALUE(Spalten2[Spalte])
Return
SWITCH(TRUE(),Spalte="Month", CALCULATE([H_R_Month]), Spalte="YTD", CALCULATE([H_R_YTD]))

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



I tried this already, but i have the problem that i have measures that only need to be displayed in YTD.

When i am creating then the following measure: 

Test_Value =
VAR Spalte = SELECTEDVALUE(Spalten2[Spalte])
Return
SWITCH(TRUE(),Spalte="YTD", CALCULATE([Test_Value]))


This value is also displayed under Month...the easiest way would be to remove than these columns but i couldnt find any solution to this until now...

Hi @Krexx ,

 

What you need to do then is to add an extra level to your MTD YTD table with the measures you need and then use the syntax in a different way.

 

Something similar to this:

ID

Spalte Measure

1

Monat Measure 1
2 Monat Measure 2
3 YTD Measure 3
4 YTD Measure 4
5 YTD Measure 5

 

Now do the following measure:

_H_R_Monat_Test =
VAR Spalte = SELECTEDVALUE(Spalten2[ID])
Return
SWITCH(TRUE(),
Spalte= 1, CALCULATE([Measure 1]),
Spalte= 2, CALCULATE([Measure 2]),
Spalte= 3, CALCULATE([Measure 3]),
Spalte= 4, CALCULATE([Measure 4]),
Spalte= 5, CALCULATE([Measure 5])
)

 

Add both levels to matrix hierarchy and this measure to the values.

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @MFelix, thanks for your idea, it workes nearly perfect. 

But now i am having following scenario which i cant explain. My Measure looks like this: 

_H_R_Monat_Test = 
Var Spalte= SELECTEDVALUE(Spalten[ID])
Return
SWITCH(TRUE(),
Spalte=1, CALCULATE([H_R_Monat]),
Spalte=2, CALCULATE([H_A_Monat]),
Spalte=3, CALCULATE([H_Ist_Gesch_M]),
Spalte=4, CALCULATE([H_P_Monat]),
Spalte=5, CALCULATE([H_Abw_Monat]),
Spalte=6, CALCULATE([H_in%_Monat]),
Spalte=10, CALCULATE([H_R_YTD]),
Spalte=11, CALCULATE([H_A_YTD]),
Spalte=12, CALCULATE([H_Ist_Gesch_YTD]),
Spalte=13, CALCULATE([H_P_YTD]),
Spalte=14, CALCULATE([H_Abw_YTD]),
Spalte=15, CALCULATE([H_in%_YTD]),
Spalte=19, CALCULATE([H_P_Year]),
Spalte=20, CALCULATE([H_P_Monat])
)

When i use alle the columns from the second table in my matrix i can see all the columns perfectly.

Krexx_0-1611600591387.png

But as soon as i remove the ID from the Columns, it looks like this: 

Krexx_1-1611600634675.png

Some values are missing, had you ever experienced the same problem? 

Thanks in advance

 


'

 

Anonymous
Not applicable

Hi @Krexx,

Can you please share a pbix file with some dummy data? It should help us clarify these scenarios and test these expressions.

How to Get Your Question Answered Quickly 

Notice: please not attach sensitive data in your sample.

Regards,

Xiaoxin Sheng

Hi @Krexx 

 

Instead of using a variable use the syntax within the switch measure:

SWITCH(SELECTEDVALUE(Spalten[ID]),
1, CALCULATE([H_R_Monat]),
2, CALCULATE([H_A_Monat]),
3, CALCULATE([H_Ist_Gesch_M]),
4, CALCULATE([H_P_Monat]),
5, CALCULATE([H_Abw_Monat]),
6, CALCULATE([H_in%_Monat]),
10, CALCULATE([H_R_YTD]),
11, CALCULATE([H_A_YTD]),
12, CALCULATE([H_Ist_Gesch_YTD]),
13, CALCULATE([H_P_YTD]),
14, CALCULATE([H_Abw_YTD]),
15, CALCULATE([H_in%_YTD]),
19, CALCULATE([H_P_Year]),
20, CALCULATE([H_P_Monat])
)

 

 

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @Krexx  

 

Just for your information this has to do with the context transiction, since you were using the Variable that is calculated before the function you need the context is given before the calculation so you need to have the ID column on the visualization, when you place the ID in within the switch function the table context is first loaded and then the ID is already consider for the calculation so the corresponding rows of each ID appear normally.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Awesome, thank you very much 🙂 !!!!!

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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