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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
FilipK
Resolver I
Resolver I

Pivot column with two value columns (condition)

The task

I want to pivot this dataset:

 

namevalueDoubleMaxvalueStringMaxepoch_time
f121null1,60551E+12
f2nullCDE65563-CPX11,60551E+12
f399null1,60551E+12
f492null1,60551E+12
f537594612null1,60551E+12
f6-5129null1,60551E+12
f736938751null1,60551E+12
f8-19null1,60551E+12
f982null1,60551E+12
f1099null1,60552E+12
f1193null1,60552E+12
f1237597793null1,60552E+12
f13-5137null1,60552E+12
f1436941932null1,60552E+12
f15-14null1,60552E+12

 

Whenever valueDoubleMax=null the other column shall be used as value column in pivot context.

Desired output

epochtimef1f2f3f4f5f6f7f8f9f10f11f12f13f14f15
1,61E+1221CDE65563-CPX1999237594612-512936938751-1982999337597793-513736941932-14

 

Problem

Since pivot column function in power query editor only supports one column I wonder how to do it.

 

Ideas

In SQL the approach would be the following:

 

select * from (
  select epoch_time, max(CASE WHEN name = 'f1' THEN value_string END) f1
...
 
No options
I don't want to use SQL statement at query start, since I need to run an incremental refresh later on. SQL view is also not wished.
Also a merge into one string column is not desired (dataset size)
 
 
What is your recommendation?
1 ACCEPTED SOLUTION

Hi @FilipK ,

For native query, when you changed data type, the folding will be triggered and you can see it.

NQ.png

For incremental refresh, the data type of refresh parameter can only be the date type.

You can refer this blog about incremental refresh: Keep The Existing Data In Your Power BI Dataset And Add New Data To It Using Incremental Refresh 

 

Best Regards,
Community Support Team _ Yingjie Li
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

7 REPLIES 7
CNENFRNL
Community Champion
Community Champion

@FilipK , you might want to combine those 2 columns this way,

 

#"Column Combined" = Table.AddColumn(#"Previous Step", "Custom", each (Text.From([valueDoubleMax]) ?? "") & ([valueStringMax] ?? ""))

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

@CNENFRNL , that's nice. I didn't notice that this is possible. The solution has one drawback, for it appears that it's not able to be folded. Is there any other possibility?

FilipK_0-1606556122560.png

 

Hi @FilipK ,

Seems like you are using Direct Query mode to connect to your data source. If you want to create the new column and see te Native Query at the same time, you can try these steps:

1. Change the data type of [valueDoubleMax] from number to text

2. Replace the null value in [valueDoubleMax] and [valueStringMax] from null to ""(Blank)

replace value.png

3. Add a custom column to combine these two columns

 

= Table.AddColumn(#"Replaced Value1", "Custom", each [valueDoubleMax] & [valueStringMax])

 

query.png 

Now you can check the native query and it should work, you can also use this column to pivot columns as your need.

In conclusion, the whole query may look like this:

 

let
    Source = Sql.Databases("xxx"),
    xxxx = Source{[Name="xxxx"]}[Data],
    dbo_Pivot_table = xxxx{[Schema="dbo",Item="Pivot_table"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(dbo_Pivot_table,{{"valueDoubleMax", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type",null,"",Replacer.ReplaceValue,{"valueDoubleMax"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value",null,"",Replacer.ReplaceValue,{"valueStringMax"}),
    #"Added Custom" = Table.AddColumn(#"Replaced Value1", "Custom", each [valueDoubleMax] & [valueStringMax])
in
    #"Added Custom"

 

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hey @v-yingjl . Thanks for your recommondation. I've already thought about it and came to the clue that this is not possible for typechange is not allowed for folding/ incremental refresh. Am I wrong? If so, it could be an option even I'm afraid of increasing the dataset a lot (number -> string). 

 

Direct query is not used.

Hi @FilipK ,

For native query, when you changed data type, the folding will be triggered and you can see it.

NQ.png

For incremental refresh, the data type of refresh parameter can only be the date type.

You can refer this blog about incremental refresh: Keep The Existing Data In Your Power BI Dataset And Add New Data To It Using Incremental Refresh 

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

mahoneypat
Microsoft Employee
Microsoft Employee

Please show your desired output table.  Not sure which column you want to pivot on (i.e., which should be the column headers).

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Original post updated.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Solution Authors