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
arlequin71
Helper II
Helper II

Newbie Question : DAX to compare the last not empty column against other column

Hello, anyone can help me on this....

I have 4 columns displaying 4 Weekly Estimates that shoud be compared sequencially during the month against the Forecast column.  I need to write a dax (or another method) to select the Last non blank column (or measure) to compare it with the Forecast.

Thanks in advance for your help.2019-04-01_18h02_54.png

 

 

 

 

 

 

 

 

 

 

 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCk7MSS1WCEotMFTSUTIyAAIQbQSloXwQitVBUqxgBBQyhqm2hNKmOFQbA0UMzSCShuaEjDYByZqjGmmMU7UpSJUZmrMNkVTHAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Sales Rep" = _t, Forecast = _t, #"Estimate 1" = _t, #"Estimate 2" = _t, #"Estimate 3" = _t, #"Estimate 4" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Sales Rep", type text}, {"Forecast", Int64.Type}, {"Estimate 1", Int64.Type}, {"Estimate 2", Int64.Type}, {"Estimate 3", type text}, {"Estimate 4", type text}})
in
    #"Changed Type"

 

 

2 ACCEPTED SOLUTIONS
v-shex-msft
Community Support
Community Support

Hi @arlequin71 ,

You can do unpivot columns on your query table columns, then you can simply write a formula to find out last non blank estimates value based on current sales rep group.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCk7MSS1WCEotMFTSUTIyAAIQbQSloXwQitVBUqxgBBQyhqm2hNKmOFQbA0UMzSCShuaEjDYByZqjGmmMU7UpSJUZmrMNkVTHAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Sales Rep" = _t, Forecast = _t, #"Estimate 1" = _t, #"Estimate 2" = _t, #"Estimate 3" = _t, #"Estimate 4" = _t]),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {"Sales Rep", "Forecast"}, "Estimate", "Value"),
    #"Replaced Value" = Table.ReplaceValue(#"Unpivoted Columns","Estimate ","",Replacer.ReplaceText,{"Estimate"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Replaced Value",{{"Sales Rep", type text}, {"Forecast", Int64.Type}, {"Estimate", Int64.Type},{"Value", type text}})
in
    #"Changed Type"

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

Thanks a Lot... it works!

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @arlequin71 ,

You can do unpivot columns on your query table columns, then you can simply write a formula to find out last non blank estimates value based on current sales rep group.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCk7MSS1WCEotMFTSUTIyAAIQbQSloXwQitVBUqxgBBQyhqm2hNKmOFQbA0UMzSCShuaEjDYByZqjGmmMU7UpSJUZmrMNkVTHAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Sales Rep" = _t, Forecast = _t, #"Estimate 1" = _t, #"Estimate 2" = _t, #"Estimate 3" = _t, #"Estimate 4" = _t]),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {"Sales Rep", "Forecast"}, "Estimate", "Value"),
    #"Replaced Value" = Table.ReplaceValue(#"Unpivoted Columns","Estimate ","",Replacer.ReplaceText,{"Estimate"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Replaced Value",{{"Sales Rep", type text}, {"Forecast", Int64.Type}, {"Estimate", Int64.Type},{"Value", type text}})
in
    #"Changed Type"

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thanks a Lot... it works!

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.