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

sCalculate the sum for first value other should be blank

I want to calculate the dax for below table

 

PrasanthSara22_0-1675402912991.png

 

 

This need to calculate based on date and name.

Same date and same name means first value should be sum other will be blank

1 ACCEPTED SOLUTION

Hi @PrasanthSara22 

 

Here is my solution with Power Query. Hope it helps. 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtY31Dc2UNJRcgRip6LUxGwgbWigFKuDW9oIv7QxprQTfsORpU0JycYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Name = _t, Activity = _t, Time = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Name", type text}, {"Activity", type text}, {"Time", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date", "Name"}, {{"All Rows", each Table.AddIndexColumn(_, "Index", 1, 1), type table}, {"Total", each List.Sum([Time]), type nullable number}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Grouped Rows",{"All Rows", "Total"}),
    #"Expanded All Rows" = Table.ExpandTableColumn(#"Removed Other Columns", "All Rows", {"Date", "Name", "Activity", "Time", "Index"}, {"Date", "Name", "Activity", "Time", "Index"}),
    #"Replaced Value" = Table.ReplaceValue(#"Expanded All Rows", each if [Index] <> 1 then [Total] else false, each 0, Replacer.ReplaceValue, {"Total"})
in
    #"Replaced Value"

vjingzhang_0-1675662700927.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

3 REPLIES 3
PrasanthSara22
Frequent Visitor

Anything is fine. Please help me

 

Hi @PrasanthSara22 

 

Here is my solution with Power Query. Hope it helps. 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtY31Dc2UNJRcgRip6LUxGwgbWigFKuDW9oIv7QxprQTfsORpU0JycYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Name = _t, Activity = _t, Time = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Name", type text}, {"Activity", type text}, {"Time", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date", "Name"}, {{"All Rows", each Table.AddIndexColumn(_, "Index", 1, 1), type table}, {"Total", each List.Sum([Time]), type nullable number}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Grouped Rows",{"All Rows", "Total"}),
    #"Expanded All Rows" = Table.ExpandTableColumn(#"Removed Other Columns", "All Rows", {"Date", "Name", "Activity", "Time", "Index"}, {"Date", "Name", "Activity", "Time", "Index"}),
    #"Replaced Value" = Table.ReplaceValue(#"Expanded All Rows", each if [Index] <> 1 then [Total] else false, each 0, Replacer.ReplaceValue, {"Total"})
in
    #"Replaced Value"

vjingzhang_0-1675662700927.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

lbendlin
Super User
Super User

Does it have to be DAX?  Would be much simpler in Power Query.

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
Top Kudoed Authors