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
datatbl123
Helper I
Helper I

Change the amount of a value in a column if certain conditions are met

Hi,

 

I would like for the value in my Count column to change from a 1 to a 0.5 but only if the person's name in my Scheduled Person column is the same 2 days in a row (back to back days) from my Appt date column. Also the Procedure needs to be equal to A and the Center needs to be equal B.

 

Screenshot 2022-12-15 095407.jpg

1 ACCEPTED SOLUTION
3 REPLIES 3
JW_van_Holst
Resolver IV
Resolver IV

Here is the code with the solution. The main part is the group-by with group-kind local as 4th argument (no in the UI). Good luck.

Picture1.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZcxLCsAgDIThu2QtTJKqrcs+LxG8/zVaQhVLYVYfw29GCTJBWZUCrVSDUYQsTTaXAslNdhcRPHvpcMrD6XThAu6lq9P8JWFw/FMaqN4=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Person = _t]),
    #"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"Date", type date}}, "en-US"),
    SortedRows = Table.Buffer(Table.Sort(#"Changed Type with Locale",{{"Date", Order.Ascending}})),
    #"Grouped Rows" = Table.Group(SortedRows, {"Person"}, {{"Count local", each Table.RowCount(_), Int64.Type}, {"Data", each _, type table [Date=nullable date, Person=nullable text]}}, GroupKind.Local),
    #"Removed Columns" = Table.RemoveColumns(#"Grouped Rows",{"Person"}),
    #"Expanded Data" = Table.ExpandTableColumn(#"Removed Columns", "Data", {"Date", "Person"}, {"Date", "Person"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Data", "factor", each if [Count local] >= 2 then 0.5 else 1)
in
    #"Added Custom"

 

 

Do you have a custom solution in DAX? I have to insert multiple arguments depending on the type of procedure and center location. Thank you.

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