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
mariajuliao
Frequent Visitor

Transposing / Transforming data with DAX

I want to transform the data from this format:

IDCaseNumberAsset1Asset2
AABB12
CCDD34

 

To this format:

IDCaseNumberAssetValue
AABBAsset11
AABBAsset22
CCDDAsset13
CCDDAsset24

 

Since columns Asset1, Asset2, Asset3, etc. are calculated column in DAX I cannot use PowerQuery to unpivot the data. Let me know any solutions with DAX. 

 

Thanks!!

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

It's a bit manual, but you can do it as I demonstrated here:

https://stackoverflow.com/questions/50213905/is-it-possible-to-unpivot-in-power-bi-using-dax

 

UNION (
    SELECTCOLUMNS (
        T,
        "ID",         T[ID],
        "CaseNumber", T[CaseNumber],
        "Asset",      "Asset1",
        "Value",      T[Asset1]
    ),
    SELECTCOLUMNS (
        T,
        "ID",         T[ID],
        "CaseNumber", T[CaseNumber],
        "Asset",      "Asset2",
        "Value",      T[Asset2]
    )
)

View solution in original post

5 REPLIES 5
AlexisOlson
Super User
Super User

It's a bit manual, but you can do it as I demonstrated here:

https://stackoverflow.com/questions/50213905/is-it-possible-to-unpivot-in-power-bi-using-dax

 

UNION (
    SELECTCOLUMNS (
        T,
        "ID",         T[ID],
        "CaseNumber", T[CaseNumber],
        "Asset",      "Asset1",
        "Value",      T[Asset1]
    ),
    SELECTCOLUMNS (
        T,
        "ID",         T[ID],
        "CaseNumber", T[CaseNumber],
        "Asset",      "Asset2",
        "Value",      T[Asset2]
    )
)

This was very helpful!!

 

One other question -- Some of the values under the Asset1, Asset2 columns are blank. Is there any way that I can ommit those? 

You can wrap a FILTER around the whole thing.

 

FILTER ( 
    UNION ( 
        [...]
    ),
    NOT ISBLANK ( [Asset] )
)
VahidDM
Super User
Super User

Hi @mariajuliao 

 

Try this code to create a new table with DAX:

 

Table 2 =
VAR _A =
    SUMMARIZE ( 'Table', 'Table'[ID], 'Table'[CaseNumber] )
VAR _B =
    SELECTCOLUMNS ( { "Asset1", "Asset2" }, "Asset", [Value] )
VAR _C =
    CROSSJOIN ( _A, _B )
VAR _ASSET =
    ADDCOLUMNS (
        _C,
        "Value",
            IF (
                [Asset] = "Asset1",
                CALCULATE (
                    MAX ( 'Table'[Asset1] ),
                    FILTER (
                        'Table',
                        'Table'[ID] = EARLIER ( [ID] )
                            && 'Table'[CaseNumber] = EARLIER ( [CaseNumber] )
                    )
                ),
                CALCULATE (
                    MAX ( 'Table'[Asset2] ),
                    FILTER (
                        'Table',
                        'Table'[ID] = EARLIER ( [ID] )
                            && 'Table'[CaseNumber] = EARLIER ( [CaseNumber] )
                    )
                )
            )
    )
RETURN
    _ASSET

 

 

Output:

VahidDM_0-1646346421607.png

 

 

 

Sample file attached.

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

This was very helpful!!

 

One other question -- Some of the values under the Asset1, Asset2 columns are blank. Is there any way that I can ommit those? 

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