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
DonRoberto1985
New Member

Conditional Table

Hi,

 

I'm breaking my head on this thing 🙂

 

I want to see only one entry per month of a device(ResID) on the following (prioritized) condition: If all of them are compliant, then as compliant. If one of them is non-compliant then as non-compliant, If one of them is null then as null.

 

DonRoberto1985_0-1673520980958.png

 

Thanks in advance,

Robert

2 ACCEPTED SOLUTIONS

Hi, 

you can obtain this result

serpiva64_0-1673532854955.png

applaying the steps of the attache file

If this post isuseful to help you to solve your issue consider giving the post a thumbs up and accepting it as a solution !

View solution in original post

AlB
Super User
Super User

Hi @DonRoberto1985 

Place the following M code in a blank query to see the steps.

You might have to change

[LastComplianceMessageDesc] = ""

for

[LastComplianceMessageDesc] = null

in the #"Added Custom" step 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZK9CoNAEIRfRa424OxF91Lb5wXEIlgJRlP4/uTUKAZOdrq9m49h9qdpHCpVDRJc7p7TeOum92foX+Mc31KIzxALuDb/I2uKOovesJDsEQs1qeUzmJSmvHaxouIsVGlSJeV1pyifonZRiDVslJgUhBo1wGFFaiWHyiUiKKwruTgybE3ZHkgO8lC5IPide/sF", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ResID = _t, LastComplianceMessageDesc = _t, Date = _t, Count = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ResID", Int64.Type}, {"LastComplianceMessageDesc", type text}, {"Date", type date}, {"Count", Int64.Type}}),

    #"Added Custom" = Table.AddColumn(#"Changed Type", "Sorting", each if [LastComplianceMessageDesc] = "Non-compliant" then 1 else if [LastComplianceMessageDesc] = "" then 2 else 3, Int64.Type),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"ResID", "Date"}, {{"Count", each Table.Min(_, "Sorting")}}),
    #"Expanded Count" = Table.ExpandRecordColumn(#"Grouped Rows", "Count", {"LastComplianceMessageDesc", "Count"}, {"LastComplianceMessageDesc", "Count"})
in
    #"Expanded Count"

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

View solution in original post

5 REPLIES 5
DonRoberto1985
New Member

Thanks a lot 🙂

AlB
Super User
Super User

Hi @DonRoberto1985 

Place the following M code in a blank query to see the steps.

You might have to change

[LastComplianceMessageDesc] = ""

for

[LastComplianceMessageDesc] = null

in the #"Added Custom" step 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZK9CoNAEIRfRa424OxF91Lb5wXEIlgJRlP4/uTUKAZOdrq9m49h9qdpHCpVDRJc7p7TeOum92foX+Mc31KIzxALuDb/I2uKOovesJDsEQs1qeUzmJSmvHaxouIsVGlSJeV1pyifonZRiDVslJgUhBo1wGFFaiWHyiUiKKwruTgybE3ZHkgO8lC5IPide/sF", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ResID = _t, LastComplianceMessageDesc = _t, Date = _t, Count = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ResID", Int64.Type}, {"LastComplianceMessageDesc", type text}, {"Date", type date}, {"Count", Int64.Type}}),

    #"Added Custom" = Table.AddColumn(#"Changed Type", "Sorting", each if [LastComplianceMessageDesc] = "Non-compliant" then 1 else if [LastComplianceMessageDesc] = "" then 2 else 3, Int64.Type),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"ResID", "Date"}, {{"Count", each Table.Min(_, "Sorting")}}),
    #"Expanded Count" = Table.ExpandRecordColumn(#"Grouped Rows", "Count", {"LastComplianceMessageDesc", "Count"}, {"LastComplianceMessageDesc", "Count"})
in
    #"Expanded Count"

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

serpiva64
Super User
Super User

Please can you paste data (not images) and the required result?

Data:

ResIDLastComplianceMessageDescDateCount
16777828Non-compliant2023 11
16777828Compliant2023 11
16777828null2023 13
16777828Compliant2022 97
16777828Compliant2022 88
16777828Compliant2022 77
16777828null2022 63
16777828Compliant2022 65
16777828Compliant2022 53
16777828Compliant2022 43
16777828Compliant2022 33
16777828null2022 21
16777828Compliant2022 22
16777828Compliant2022 127
16777828Compliant2022 117
16777828Compliant2022 108
16777828null2022 12
16777828Compliant2022 12
16777828Compliant2021 61
16777828null2021 122
16777828Compliant2021 121
16777828null2021 112
16777828Compliant2021 111

 

Result:

ResIDLastComplianceMessageDescDateCount
16777828Non-compliant2023 11
16777828Compliant2022 97
16777828Compliant2022 88
16777828Compliant2022 77
16777828null2022 63
16777828Compliant2022 53
16777828Compliant2022 43
16777828Compliant2022 33
16777828null2022 21
16777828Compliant2022 127
16777828Compliant2022 117
16777828Compliant2022 108
16777828null2022 12
16777828Compliant2021 61
16777828null2021 122
16777828null2021 112

 

Thanks 🙂

Hi, 

you can obtain this result

serpiva64_0-1673532854955.png

applaying the steps of the attache file

If this post isuseful to help you to solve your issue consider giving the post a thumbs up and accepting it as a solution !

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