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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ale-hd
Helper I
Helper I

How to change the data reference of a measure

I all,

I have a table with some data columns

                               A             B             C             D            

10/11/2019         120         132         87           150

11/11/2019         110         121         83           143

…..

and some measures that are always the same formula but referred to different data columns

i.e.

MEASURE 1  = CALCULATE(SUM[A];FILTER(Basedati;(Basedati[Stato]="Cancellazione" && Basedati[Data modifica stato]<=maxlettura) || (Basedati[Stato]="No Show" && Basedati[Dal]<maxlettura)))

 

MEASURE 2  = CALCULATE(SUM[B];FILTER(Basedati;(Basedati[Stato]="Cancellazione" && Basedati[Data modifica stato]<=maxlettura) || (Basedati[Stato]="No Show" && Basedati[Dal]<maxlettura)))

 

MEASURE 3 = CALCULATE(SUM[C];….

….

 

Is there anyway to write just the First Measure and for the others make something like following?

 

MEASURE 2 = MEASURE 1 but use [B] instead of [A]

 

MEASURE 2 = MEASURE 1 but use [C] instead of [A]

 

Thank you very much,

Alessandro

1 ACCEPTED SOLUTION

Sorry if I was unclear. What I meant was that if you want to keep your current table structure, there is no other solution than keep on doing what you already are doing, writing a measure for each column. There is no way in Power BI to write that measure once, and then replace the column as you suggest.

 

An alternative solution would be to reorganize your table(s), by unpivoting your table(s). Depending on your tables it might also be something to gain from splitting them up into several tables before unpivoting.

View solution in original post

5 REPLIES 5
v-frfei-msft
Community Support
Community Support

Hi @ale-hd ,

 

We can unpivot the table as below. 

Capture.PNG

 

M code for your reference.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMLRU0lEyNDIAkcZGQNLCXClWByRrBJc1BMsaGYJkjZViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t, A = _t, B = _t, C = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"A", Int64.Type}, {"B", Int64.Type}, {"C", Int64.Type}})
in
    #"Changed Type"

 

After that, we can create measure as your want and add it to matrix to show the data. For more details, please check the pbix as attached.

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Kudos for the time you dedicate to me, thank you, unfortunately I cannot split the table.
sturlaws
Resident Rockstar
Resident Rockstar

Hi @ale-hd,

 

nope, with you table structure you have to write the code for each measure.

 

But, I am pretty sure you can reorganize your data so that you the column names as rows. This will allow you do write a single measure that can be reused.

Date    ColName      Value

søndag 10. november 2019A120
søndag 10. november 2019B132
søndag 10. november 2019C87
søndag 10. november 2019D150
mandag 11. november 2019A110
mandag 11. november 2019B121
mandag 11. november 2019C83
mandag 11. november 2019D143


Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

Thank you Sturla, unfortunately the solution "you have to write the code for each measure" is the one I am using now and it is really uncomfortable. The real measures I am using are much more complex than the ones I reported in the post and are mnay different ones.

 

 

Sorry if I was unclear. What I meant was that if you want to keep your current table structure, there is no other solution than keep on doing what you already are doing, writing a measure for each column. There is no way in Power BI to write that measure once, and then replace the column as you suggest.

 

An alternative solution would be to reorganize your table(s), by unpivoting your table(s). Depending on your tables it might also be something to gain from splitting them up into several tables before unpivoting.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors