Forum Discussion
Add custom Row based on Dax logic
Thanks for the reply from Poojara_D12 and DataNinja777, please allow me to provide another insight:
Hi, Puja
Could you please let me know if the responses from Poojara_D12 and DataNinja777 have resolved your issue?
If it did, kindly accept it as the solution.
Below is my M language solution to your problem:
let
// Load your transaction data
Source = Table.FromRows(
{
{"ID001", "Wages - Temp Staff", 1000},
{"ID001", "Payroll Tax Temp", 200},
{"ID002", "Wages - Temp Staff", 1500},
{"ID002", "Payroll Tax Temp", 300}
},
{"ID", "Type", "Value"}
),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Type", type text}, {"Value", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Value", each List.Sum([Value])*-1, type nullable number}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Type", each "Asset Purchases"),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Type", type text}}),
#"Appended Query" = Table.Combine({#"Changed Type1", #"Changed Type"}),
#"Sorted Rows" = Table.Sort(#"Appended Query",{{"ID", Order.Ascending}})
in
#"Sorted Rows"
Here is my sample data:
The final result is as follows:
Of course, Poojara_D12 's UNION() function is also a good solution. To facilitate your understanding, I have also created the following example.
Here's my final result, which I hope meets your requirements.
For further details, please refer to:
UNION function (DAX) - DAX | Microsoft Learn
SUMMARIZE function (DAX) - DAX | Microsoft Learn
Please find the attached pbix relevant to the case.
Best Regards,
Leroy Lu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.