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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
buttercream
Helper II
Helper II

Reformat table

Hello,

 

How do I transform this table preferably in DAX as calculated table:

 

InvoiceDateHas nameHas address
1531/1/2024YesYes
1541/1/2024YesYes
1551/1/2024NoYes
1561/2/2024YesNo
1571/2/2024YesNo
1581/2/2024YesYes
1591/3/2024NoNo
1601/3/2024NoNo

 

Into this:

DateTest% Yes
1/1/2024Has name66.67%
1/1/2024Has address100.00%
1/2/2024Has name100.00%
1/2/2024Has address33.33%
1/3/2024Has name0.00%
1/3/2024Has address0.00%
1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @buttercream -Open Power Query Editor by clicking on Transform Data.
Unpivot Columns

Select the columns Has name and Has address.
Right-click on the selected columns and choose Unpivot Columns.
This will create two new columns: Attribute (with the values "Has name" and "Has address") and Value (with the values "Yes" and "No").
Rename Columns

Rename the Attribute column to Test.
Rename the Value column to % Yes.
Replace "Yes" and "No"

Replace "Yes" with 1 and "No" with 0 in the % Yes column.
Select the % Yes column.
Go to Transform > Replace Values.
Group Data

Select the Date and Test columns.
Go to Home > Group By.
In the Group By window:
Set Group By to Date and Test.
Set Operation to Average on % Yes and name it Average.
Convert Average to Percentage

Change the data type of the Average column to Percentage or multiply by 100 to format as a percentage.
Rename the Average Column

Rename the Average column to % Yes.
Load Data Back

Click Close & Apply to load the transformed data back into Power BI.

 

advanced M code FYR:

 

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ1VtJRMtQ31DcyMDIBMiNTi6FkrA5I2gS/tCmqtF8+iqwZWNYIVTNQDUTWHK+sBTZZhNGWYGljFIthes0McEjGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Invoice = _t, Date = _t, #"Has name" = _t, #"Has address" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Invoice", Int64.Type}, {"Date", type date}, {"Has name", type text}, {"Has address", type text}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Invoice", "Date"}, "Attribute", "Value"),
#"Renamed Columns" = Table.RenameColumns(#"Unpivoted Columns",{{"Attribute", "Test"}, {"Value", "% Yes"}}),
#"Replaced Value" = Table.ReplaceValue(#"Renamed Columns","Yes","1",Replacer.ReplaceText,{"% Yes"}),
#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","No","0",Replacer.ReplaceText,{"% Yes"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value1",{{"% Yes", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type1", {"Date", "Test"}, {{"Average", each List.Average([#"% Yes"]), type nullable text}}),
#"Changed Type2" = Table.TransformColumnTypes(#"Grouped Rows",{{"Average", Percentage.Type}}),
#"Renamed Columns1" = Table.RenameColumns(#"Changed Type2",{{"Average", "Yes"}})
in
#"Renamed Columns1"

 

rajendraongole1_0-1735390995799.png

 





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

Proud to be a Super User!





View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

Would you be OK with a Power Query and measure solution?  Why do you need a calculated table solution?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
danextian
Super User
Super User

Hi @buttercream 

 

Things like this are better than in the query editor than in DAX but for the sake of whether it is is possible, please see below:

danextian_0-1735399034844.png

Reformatted = 
VAR _hasname =
    SELECTCOLUMNS (
        Source,
        "Date", Source[Date],
        "Invoice", Source[Invoice],
        "Test", "Has name",
        "Value", Source[Has name]
    )
VAR _hasaddress =
    SELECTCOLUMNS (
        Source,
        "Date", Source[Date],
        "Invoice", Source[Invoice],
        "Test", "Has address",
        "Value", Source[Has address]
    )
VAR _combined =
    UNION ( _hasname, _hasaddress )
VAR _grouped01 =
    GROUPBY (
        _combined,
        [Date],
        [Test],
        [Value],
        "Count", COUNTX ( CURRENTGROUP (), 1 )
    )
VAR _percentageTable =
    ADDCOLUMNS (
        _grouped01,
        "YesCount",
            VAR _test = [Test]
            VAR _date = [Date]
            RETURN
                CALCULATE (
                    SUMX (
                        FILTER ( _grouped01, [Value] = "Yes" && [Test] = _test && [Date] = _date ),
                        [Count]
                    )
                ),
        "TotalCount",
            VAR _test = [Test]
            VAR _date = [Date]
            RETURN
                CALCULATE (
                    SUMX ( FILTER ( _grouped01, [Test] = _test && [Date] = _date ), [Count] )
                )
    )
VAR _finalTable =
    ADDCOLUMNS (
        _percentageTable,
        "Percentage", DIVIDE ( [YesCount], [TotalCount], 0 ) + 0
    )
RETURN
    GROUPBY ( _finalTable, [Test], [Date], [Percentage] )

Source is the name of the table containing the original data format.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thanks.

rajendraongole1
Super User
Super User

Hi @buttercream -Open Power Query Editor by clicking on Transform Data.
Unpivot Columns

Select the columns Has name and Has address.
Right-click on the selected columns and choose Unpivot Columns.
This will create two new columns: Attribute (with the values "Has name" and "Has address") and Value (with the values "Yes" and "No").
Rename Columns

Rename the Attribute column to Test.
Rename the Value column to % Yes.
Replace "Yes" and "No"

Replace "Yes" with 1 and "No" with 0 in the % Yes column.
Select the % Yes column.
Go to Transform > Replace Values.
Group Data

Select the Date and Test columns.
Go to Home > Group By.
In the Group By window:
Set Group By to Date and Test.
Set Operation to Average on % Yes and name it Average.
Convert Average to Percentage

Change the data type of the Average column to Percentage or multiply by 100 to format as a percentage.
Rename the Average Column

Rename the Average column to % Yes.
Load Data Back

Click Close & Apply to load the transformed data back into Power BI.

 

advanced M code FYR:

 

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ1VtJRMtQ31DcyMDIBMiNTi6FkrA5I2gS/tCmqtF8+iqwZWNYIVTNQDUTWHK+sBTZZhNGWYGljFIthes0McEjGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Invoice = _t, Date = _t, #"Has name" = _t, #"Has address" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Invoice", Int64.Type}, {"Date", type date}, {"Has name", type text}, {"Has address", type text}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Invoice", "Date"}, "Attribute", "Value"),
#"Renamed Columns" = Table.RenameColumns(#"Unpivoted Columns",{{"Attribute", "Test"}, {"Value", "% Yes"}}),
#"Replaced Value" = Table.ReplaceValue(#"Renamed Columns","Yes","1",Replacer.ReplaceText,{"% Yes"}),
#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","No","0",Replacer.ReplaceText,{"% Yes"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value1",{{"% Yes", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type1", {"Date", "Test"}, {{"Average", each List.Average([#"% Yes"]), type nullable text}}),
#"Changed Type2" = Table.TransformColumnTypes(#"Grouped Rows",{{"Average", Percentage.Type}}),
#"Renamed Columns1" = Table.RenameColumns(#"Changed Type2",{{"Average", "Yes"}})
in
#"Renamed Columns1"

 

rajendraongole1_0-1735390995799.png

 





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

Proud to be a Super User!





Thank you so much.

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.