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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
Vish_korg
Frequent Visitor

Error in unpivot DAX query

I have created table "H1_daily" where I have the following data

Equipment failure lossSetup & adjustment loss
2010
305
158
106

I want the output as follows

Total lossesDown time
Equipment failure loss20
Setup & adjustment loss10
Equipment failure loss30
Setup & adjustment loss5
Equipment failure loss15
Setup & adjustment loss8
Equipment failure loss10
Setup & adjustment loss6

 

I have used the query

Down_time = union(
          SELECTCOLUMNS('H1_daily',"Total losses","Equipment failure loss",'H1_daily'[Equipment failure loss]),
          SELECTCOLUMNS('H1_daily',"Total Losses","Setup & adjustment loss",'H1_daily'[Setup & Adjustment loss]))
getting the error "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value."
Can any one help why this error is comming and what is the solution?Though I have got the solution in unpivot query 
directly I want to know what is wrong in my above query?
2 ACCEPTED SOLUTIONS
jgeddes
Super User
Super User

It looks like you are trying to create a table using a measure. 
Use this code to create a new table and then you can create the visual you are looking for.

DowntimeTable = 
UNION(
        SELECTCOLUMNS('H1_daily',"Total losses","Equipment failure loss", "Down time", 'H1_daily'[Equipment failure loss]),
        SELECTCOLUMNS('H1_daily',"Total Losses","Setup & adjustment loss","Down time", 'H1_daily'[Setup & Adjustment loss])
    )

jgeddes_0-1729789465393.png

 





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

Proud to be a Super User!





View solution in original post

Cristian_Angyal
Most Valuable Professional
Most Valuable Professional

Hey @Vish_korg ,

If you are trying to build a DAX Table then the solution provided by @jgeddes  should be ok.

On the other hand, if you aleready have the initial table in Power Query, why not UNPIVOT it there and simplify your DAX code?!?

Here is the M code to do it in PQ:

// This query processes a table containing equipment failure and setup adjustment loss data, 
// adds a custom column, unpivots the data, changes the data type of the downtime column, and removes an extra column.
// Developed by Cristian Angyal with Custom Chat GPT "Power Query Wizard"

let
    // Create initial table from compressed JSON data
    SourceTable = Table.FromRows(
        Json.Document(
            Binary.Decompress(
                Binary.FromText("i45WMjJQ0lEyNFCK1YlWMgaxTcFMQ1Mg0wLCBImaKcXGAgA=", BinaryEncoding.Base64), 
                Compression.Deflate
            )
        ), 
        let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Equipment failure loss" = _t, #"Setup & adjustment loss" = _t]
    ),

    // Add a custom column with a static value of 1 --- could be ANY value
    AddCustomColumn = Table.AddColumn(SourceTable, "Custom", each 1),

    // Unpivot all columns except the "Custom" column
    UnpivotedData = Table.UnpivotOtherColumns(AddCustomColumn, {"Custom"}, "Total Losses", "Down Time"),

    // Change the data type of the "DownTime" column to Int64
    ChangedType = Table.TransformColumnTypes(UnpivotedData, {{"Down Time", Int64.Type}}),

    // Remove the "Custom" column
    RemoveCustomColumn = Table.RemoveColumns(ChangedType, {"Custom"})

in
    // Output the final table
    RemoveCustomColumn


Hope it helps.

If this answer was helpful, please consider accepting it as the solution to help the other members find it more quickly.

 

Kudos appreciated also 😉

Cheers,

Cristian Angyal
LinkedIn  |  X (Twitter) |   Romania Power BI User Group  |  YouTube

 


 

View solution in original post

4 REPLIES 4
slorin
Super User
Super User

Hi @Cristian_Angyal 

You can use UnpivotOtherColumns without "Custom" column

 

...
AddCustomColumn = Table.AddColumn(SourceTable, "Custom", each 1),
UnpivotedData = Table.UnpivotOtherColumns(AddCustomColumn, {"Custom"}, "Total Losses", "Down Time"),
ChangedType = Table.TransformColumnTypes(UnpivotedData, {{"Down Time", Int64.Type}}),
RemoveCustomColumn = Table.RemoveColumns(ChangedType, {"Custom"})
...

 

let
Source = YourSource
UnpivotedData = Table.UnpivotOtherColumns(Source, {}, "Total Losses", "Down Time"),
ChangedType = Table.TransformColumnTypes(UnpivotedData, {{"Down Time", Int64.Type}})
in
ChangedType

Stéphane

Cristian_Angyal
Most Valuable Professional
Most Valuable Professional

Thanks @slorin .

You are right and adding and empy list works well ... but I skipped already a step, renaming the columns directly from UNPIVOT.
I wanted to show exactly what is happening, as I'm thinking of myself some years ago when M Language understanding was not as it is these days 😉.

Cristian

Cristian_Angyal
Most Valuable Professional
Most Valuable Professional

Hey @Vish_korg ,

If you are trying to build a DAX Table then the solution provided by @jgeddes  should be ok.

On the other hand, if you aleready have the initial table in Power Query, why not UNPIVOT it there and simplify your DAX code?!?

Here is the M code to do it in PQ:

// This query processes a table containing equipment failure and setup adjustment loss data, 
// adds a custom column, unpivots the data, changes the data type of the downtime column, and removes an extra column.
// Developed by Cristian Angyal with Custom Chat GPT "Power Query Wizard"

let
    // Create initial table from compressed JSON data
    SourceTable = Table.FromRows(
        Json.Document(
            Binary.Decompress(
                Binary.FromText("i45WMjJQ0lEyNFCK1YlWMgaxTcFMQ1Mg0wLCBImaKcXGAgA=", BinaryEncoding.Base64), 
                Compression.Deflate
            )
        ), 
        let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Equipment failure loss" = _t, #"Setup & adjustment loss" = _t]
    ),

    // Add a custom column with a static value of 1 --- could be ANY value
    AddCustomColumn = Table.AddColumn(SourceTable, "Custom", each 1),

    // Unpivot all columns except the "Custom" column
    UnpivotedData = Table.UnpivotOtherColumns(AddCustomColumn, {"Custom"}, "Total Losses", "Down Time"),

    // Change the data type of the "DownTime" column to Int64
    ChangedType = Table.TransformColumnTypes(UnpivotedData, {{"Down Time", Int64.Type}}),

    // Remove the "Custom" column
    RemoveCustomColumn = Table.RemoveColumns(ChangedType, {"Custom"})

in
    // Output the final table
    RemoveCustomColumn


Hope it helps.

If this answer was helpful, please consider accepting it as the solution to help the other members find it more quickly.

 

Kudos appreciated also 😉

Cheers,

Cristian Angyal
LinkedIn  |  X (Twitter) |   Romania Power BI User Group  |  YouTube

 


 

jgeddes
Super User
Super User

It looks like you are trying to create a table using a measure. 
Use this code to create a new table and then you can create the visual you are looking for.

DowntimeTable = 
UNION(
        SELECTCOLUMNS('H1_daily',"Total losses","Equipment failure loss", "Down time", 'H1_daily'[Equipment failure loss]),
        SELECTCOLUMNS('H1_daily',"Total Losses","Setup & adjustment loss","Down time", 'H1_daily'[Setup & Adjustment loss])
    )

jgeddes_0-1729789465393.png

 





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

Proud to be a Super User!





Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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