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
Anonymous
Not applicable

unpivot the data and also consider context use DAX

Hi, I want to create a combo visual and so the data needed is one common axis column and two values,

the data seems need to be unpivoted and there are many others fiters to be considered, like location and other columns not listed.

I am new user of DAX and ask for help,  could this problem can be solved use DAX?  Thank you.

null_0-1655446373228.png

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @Anonymous ,

Here are the steps you can follow:

1. Use Enter data to create a table.

vyangliumsft_0-1655864537480.png

2. Select the following columns in the power query and use Unpivot Column.

vyangliumsft_1-1655864537484.png

3. Create calculated column.

Table

left =
LEFT('Table'[Attribute],3)
right = RIGHT('Table'[Attribute],1)

vyangliumsft_2-1655864537484.png

Table2:

Right =
RIGHT('Table2'[Month],1)

vyangliumsft_3-1655864537484.png

4. Create measure.

Bar_measure =
CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),'Table'[left]="bar"&&'Table'[right]=MAX('Table2'[Right])))
Lin_measure =
CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),'Table'[left]="lin"&&'Table'[right]=MAX('Table2'[Right])))

5. Result:

vyangliumsft_4-1655864537487.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

4 REPLIES 4
v-yangliu-msft
Community Support
Community Support

Hi  @Anonymous ,

Here are the steps you can follow:

1. Use Enter data to create a table.

vyangliumsft_0-1655864537480.png

2. Select the following columns in the power query and use Unpivot Column.

vyangliumsft_1-1655864537484.png

3. Create calculated column.

Table

left =
LEFT('Table'[Attribute],3)
right = RIGHT('Table'[Attribute],1)

vyangliumsft_2-1655864537484.png

Table2:

Right =
RIGHT('Table2'[Month],1)

vyangliumsft_3-1655864537484.png

4. Create measure.

Bar_measure =
CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),'Table'[left]="bar"&&'Table'[right]=MAX('Table2'[Right])))
Lin_measure =
CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),'Table'[left]="lin"&&'Table'[right]=MAX('Table2'[Right])))

5. Result:

vyangliumsft_4-1655864537487.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

NickolajJessen
Solution Sage
Solution Sage

Throw this into your advanced editor

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTIEYmMoNleK1YlWSoLyjKDYFCyaDFJriCRsDBZOAbLMkIwAKomNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [location = _t, bar = _t, bar2 = _t, line = _t, line2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"location", type text}, {"bar", Int64.Type}, {"bar2", Int64.Type}, {"line", Int64.Type}, {"line2", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"location"}, "Attribute", "Value"),
    #"Inserted First Characters" = Table.AddColumn(#"Unpivoted Other Columns", "First Characters", each Text.Start([Attribute], 3), type text),
    #"Replaced Value" = Table.ReplaceValue(#"Inserted First Characters","bar","Jan",Replacer.ReplaceValue,{"Attribute", "Value"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","bar2","feb",Replacer.ReplaceValue,{"Attribute", "Value"}),
    #"Replaced Value2" = Table.ReplaceValue(#"Replaced Value1","line","jan",Replacer.ReplaceValue,{"Attribute", "Value"}),
    #"Replaced Value3" = Table.ReplaceValue(#"Replaced Value2","line2","feb",Replacer.ReplaceValue,{"Attribute", "Value"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value3",{{"Value", Int64.Type}})
in
    #"Changed Type1"


Then measure as so:

NickolajJessen_0-1655448191043.png

Same syntax for the line measure just with "lin" in stead

 

Anonymous
Not applicable

Thanks, it's a good way, but it seems new data source have to be created and has no relation to CONTEXT, so I am  seeking a way that use DAX 

What?


@Anonymous wrote:

Thanks, it's a good way, but it seems new data source have to be created and has no relation to CONTEXT 


I don't think you're gonna reach your goal with DAX only. Some unpivoting will be needed.

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.