Forum Discussion
EuanKonnektis
6 years agoFrequent Visitor
Calculate difference between Matrix Columns
Hi Everyone, I feel like I've seen a multitude of solutions for questions similar to my own here, but can't find the one that tackles the way my report is built! If anyone is able to help me, it ...
dax
6 years agoCommunity Support
Hi EuanKonnektis ,
You coudld try to create an index column based on date group by name like below
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTIyMDLQN9U3ATINlWJ1UATNQEx0QUNDINsYLJqEpt8IXRRkgKEBuijYBCOg4lgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [name = _t, date = _t, amount = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"name", type text}, {"date", type date}, {"amount", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"name"}, {{"all", each _, type table [name=text, date=date, amount=number]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([all],"index", 1,1)),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"all"}),
#"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"date", "amount", "index"}, {"date", "amount", "index"})
in
#"Expanded Custom"
Then use measure like below
Measure 4 =
CALCULATE ( SUM ( t2[amount] ) )
- CALCULATE (
SUM ( t2[amount] ),
FILTER ( ALLEXCEPT ( t2, t2[name] ), t2[index] = MIN ( t2[index] ) - 1 )
)
Best Regards,
Zoe Zhi
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.