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

How to build a DAX that can use a filtered dataset to add columns and rows to a table visual

Hi,

 

I am probably overthinking this, but ...

pivot.png

The table on the left has my data. Some projects have "Money". For those items I need to make a list and "join" them to the items from the same data but where type = "GOODS"

 

The chart on the right shows what I would like to see.

 

I really did try a LOT of things before I ended up here...

 

Thanks, if anyone knows the answer and would care to assist I will be extremely appreciative.

 

 

2 ACCEPTED SOLUTIONS
alena2k
Resolver IV
Resolver IV

Everything is possible, but sometimes it takes lots of clicking. Here is one way:

In Power Query
1. Duplicate query

2. Filter one for Type = MONEY

3. Filter another on for Type = GOODS and rename Type, Item, Amount to be Type1, Item1, Amount1

4. Append and sort by Project, fill down Type and Item, fill up Type1 and Item 1

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJR8vX3c40E0qHBLkDS0MBAKVYHJufu7+8SDKQdAwJ8XIPB0lhk/YMc/dwh0qZgaRdXN0yDTQ2Q5LAaHAsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Project = _t, Type = _t, Item = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project", type text}, {"Type", type text}, {"Item", type text}, {"Amount", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Type] = "MONEY"))
in
    #"Filtered Rows"
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJR8vX3c40E0qHBLkDS0MBAKVYHJufu7+8SDKQdAwJ8XIPB0lhk/YMc/dwh0qZgaRdXN0yDTQ2Q5LAaHAsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Project = _t, Type = _t, Item = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project", type text}, {"Type", type text}, {"Item", type text}, {"Amount", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Type] = "GOODS")),
    #"Renamed Columns" = Table.RenameColumns(#"Filtered Rows",{{"Type", "Type1"}, {"Item", "Item1"}, {"Amount", "Amount1"}})
in
    #"Renamed Columns"

 

 

let
    Source = Table.Combine({Table6, Table7}),
    #"Sorted Rows" = Table.Sort(Source,{{"Project", Order.Ascending}}),
    #"Filled Down" = Table.FillDown(#"Sorted Rows",{"Type", "Item"}),
    #"Filled Up" = Table.FillUp(#"Filled Down",{"Type1", "Item1"})
in
    #"Filled Up"

Load to Power BI

5.  Create table as you shown where Amount, Amount 1 will be Sum

6.  Use Conditional formating by Amount to "supress" by Rule output of Project, Type, Item if Amount is blank

7.  Do the same with Project, Type1, Item1 if Amount1 is blank (I used white on grey to demonstrate the idea)

8.  Rename column headers to if needed

 

Power BI Desktop.png

View solution in original post

v-juanli-msft
Community Support
Community Support

Hi @Quindici 

Thanks to alena2k's solution, i could use this succesfully.

Based on this, i make a test and show more details. 

 

Open Edit queries, paste the following code in advanced editor.

  "Source=****" is the original dataset, what i add and modify is from step #"filtered rows", you could see more details in my pbix.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJR8vX3c40E0qHBLkDS0MBAKVYHJufu7+8SDKQdAwJ8XIPB0lhk/YMc/dwh0qZgaRdXN0yDTQ2Q5DAMNgLKxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Project = _t, Type = _t, Item = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project", type text}, {"Type", type text}, {"Item", type text}, {"Amount", Int64.Type}}),
    #"Filtered Rows1" = Table.SelectRows(#"Changed Type", each ([Type] = "MONEY")),
    #"Filtered Rows2" = Table.SelectRows(#"Changed Type", each ([Type] = "GOODS")),
    #"Renamed Columns" = Table.RenameColumns(#"Filtered Rows2",{{"Type", "Type1"}, {"Item", "Item1"}, {"Amount", "Amount1"}}),
    #"New Source" = Table.Combine({#"Filtered Rows1", #"Renamed Columns"}),
    #"Sorted Rows" = Table.Sort(#"New Source",{{"Project", Order.Ascending}}),
    #"Filled Down" = Table.FillDown(#"Sorted Rows",{"Type", "Item"}),
    #"Filled Up" = Table.FillUp(#"Filled Down",{"Type1", "Item1"})
in
    #"Filled Up"

Then close&&apply, when you add columns in the Table visual, click on "Amount" and "Amount" field and select "sum" as below.

8.png

Create a measure and set conditional formatting for "Project","Type" and "Item" columns as below

7.png

 

 

Best Regards

Maggie

 

Community Support Team _ Maggie 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

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @Quindici 

Thanks to alena2k's solution, i could use this succesfully.

Based on this, i make a test and show more details. 

 

Open Edit queries, paste the following code in advanced editor.

  "Source=****" is the original dataset, what i add and modify is from step #"filtered rows", you could see more details in my pbix.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJR8vX3c40E0qHBLkDS0MBAKVYHJufu7+8SDKQdAwJ8XIPB0lhk/YMc/dwh0qZgaRdXN0yDTQ2Q5DAMNgLKxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Project = _t, Type = _t, Item = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project", type text}, {"Type", type text}, {"Item", type text}, {"Amount", Int64.Type}}),
    #"Filtered Rows1" = Table.SelectRows(#"Changed Type", each ([Type] = "MONEY")),
    #"Filtered Rows2" = Table.SelectRows(#"Changed Type", each ([Type] = "GOODS")),
    #"Renamed Columns" = Table.RenameColumns(#"Filtered Rows2",{{"Type", "Type1"}, {"Item", "Item1"}, {"Amount", "Amount1"}}),
    #"New Source" = Table.Combine({#"Filtered Rows1", #"Renamed Columns"}),
    #"Sorted Rows" = Table.Sort(#"New Source",{{"Project", Order.Ascending}}),
    #"Filled Down" = Table.FillDown(#"Sorted Rows",{"Type", "Item"}),
    #"Filled Up" = Table.FillUp(#"Filled Down",{"Type1", "Item1"})
in
    #"Filled Up"

Then close&&apply, when you add columns in the Table visual, click on "Amount" and "Amount" field and select "sum" as below.

8.png

Create a measure and set conditional formatting for "Project","Type" and "Item" columns as below

7.png

 

 

Best Regards

Maggie

 

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

alena2k
Resolver IV
Resolver IV

Everything is possible, but sometimes it takes lots of clicking. Here is one way:

In Power Query
1. Duplicate query

2. Filter one for Type = MONEY

3. Filter another on for Type = GOODS and rename Type, Item, Amount to be Type1, Item1, Amount1

4. Append and sort by Project, fill down Type and Item, fill up Type1 and Item 1

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJR8vX3c40E0qHBLkDS0MBAKVYHJufu7+8SDKQdAwJ8XIPB0lhk/YMc/dwh0qZgaRdXN0yDTQ2Q5LAaHAsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Project = _t, Type = _t, Item = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project", type text}, {"Type", type text}, {"Item", type text}, {"Amount", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Type] = "MONEY"))
in
    #"Filtered Rows"
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJR8vX3c40E0qHBLkDS0MBAKVYHJufu7+8SDKQdAwJ8XIPB0lhk/YMc/dwh0qZgaRdXN0yDTQ2Q5LAaHAsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Project = _t, Type = _t, Item = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project", type text}, {"Type", type text}, {"Item", type text}, {"Amount", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Type] = "GOODS")),
    #"Renamed Columns" = Table.RenameColumns(#"Filtered Rows",{{"Type", "Type1"}, {"Item", "Item1"}, {"Amount", "Amount1"}})
in
    #"Renamed Columns"

 

 

let
    Source = Table.Combine({Table6, Table7}),
    #"Sorted Rows" = Table.Sort(Source,{{"Project", Order.Ascending}}),
    #"Filled Down" = Table.FillDown(#"Sorted Rows",{"Type", "Item"}),
    #"Filled Up" = Table.FillUp(#"Filled Down",{"Type1", "Item1"})
in
    #"Filled Up"

Load to Power BI

5.  Create table as you shown where Amount, Amount 1 will be Sum

6.  Use Conditional formating by Amount to "supress" by Rule output of Project, Type, Item if Amount is blank

7.  Do the same with Project, Type1, Item1 if Amount1 is blank (I used white on grey to demonstrate the idea)

8.  Rename column headers to if needed

 

Power BI Desktop.png

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.