Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now
Hello,
I am working on trying to be able to pull a date in from another table to multiple columns depending on the logic that is listed below. I have the example data sets below as well along with what we would expect to look like.
Raw Data Source
ID # | ACTIVITY_DATE | SCORING CATEGORY | EVENT |
88197 | 6/10/2024 | 1 | |
37 | 6/18/2024 | 1 | |
50507 | 7/1/2024 | CRITICAL | |
88197 | 7/3/2024 | 1 | |
88197 | 7/5/2024 | 2 | |
37 | 7/5/2024 | MODERATE | |
50507 | 7/5/2024 | 2 | |
88197 | 7/8/2024 | 1 | |
88197 | 7/12/2024 | 1 | |
88197 | 7/30/2024 | 1 | |
37 | 8/1/2024 | 1 | |
88197 | 8/1/2024 | 1 | |
50507 | 8/5/2024 | Moderate |
Expected outcome in new table
ID # | Location | Status | Name | Type | IBT-1 | IBT-2 | IBT-3 | Moderate | High | Critical |
88197 | 1 | A | Test 1 | N | 6/10/2024 | 7/3/2024 | 7/5/2024 | 7/8/2024 | 7/12/2024 | 7/30/2024 |
37 | 2 | A | Test 2 | CM | 6/18/2024 | N/A | N/A | 7/5/2024 | 8/1/2024 | |
50507 | 3 | A | Test 3 | CD | N/A | N/A | N/A | N/A | N/A | 7/1/2024 |
There are some rows of data in the first table that should not be reflected in the new table as they would not be applicable due to them already meeting the final column "Critical".
I have been banging my head on this one for a bit as this is a pretty complex request, and I feel like I have the logic sound as well as what I could do, but I think I am just missing some threads to tie it all together.
Solved! Go to Solution.
Create a calculated column to get the occurrence
Occurrence Order =
VAR CurrentID = 'Table'[ID]
VAR CurrentDate = 'Table'[ACTIVITY_DATE]
RETURN
COUNTROWS(
FILTER(
'Table',
'Table'[ID] = CurrentID &&
'Table'[ACTIVITY_DATE] <= CurrentDate
)
)
and create another calculated column to to do the grouping
New Column 2 =
VAR OccurrenceNumber = 'Table'[Occurrence Order]
VAR ScoringCategory = 'Table'[SCORING CATEGORY]
RETURN
SWITCH(
TRUE(),
OccurrenceNumber = 4, "Moderate",
OccurrenceNumber = 5, "High",
OccurrenceNumber = 6, "Critical",
OR(ISBLANK(ScoringCategory), ScoringCategory = ""), "IBT-" & OccurrenceNumber,
ScoringCategory
)
and use a matrix table and add the following fields
Create a calculated column to get the occurrence
Occurrence Order =
VAR CurrentID = 'Table'[ID]
VAR CurrentDate = 'Table'[ACTIVITY_DATE]
RETURN
COUNTROWS(
FILTER(
'Table',
'Table'[ID] = CurrentID &&
'Table'[ACTIVITY_DATE] <= CurrentDate
)
)
and create another calculated column to to do the grouping
New Column 2 =
VAR OccurrenceNumber = 'Table'[Occurrence Order]
VAR ScoringCategory = 'Table'[SCORING CATEGORY]
RETURN
SWITCH(
TRUE(),
OccurrenceNumber = 4, "Moderate",
OccurrenceNumber = 5, "High",
OccurrenceNumber = 6, "Critical",
OR(ISBLANK(ScoringCategory), ScoringCategory = ""), "IBT-" & OccurrenceNumber,
ScoringCategory
)
and use a matrix table and add the following fields
Hi kushanNa,
This worked great, but is there a way to limit the occurence number to never exceed 3? When I run this with a larger data set there are some occurences that come up at 7 or 8. As the source data set grows overtime I think that will continue to increase.
Hi , add a >= 6 then it will stop from 6 , and change the matrix table values to latest so it will show the last occurrence date
New Column 2 =
VAR OccurrenceNumber = 'Table'[Occurrence Order]
VAR ScoringCategory = 'Table'[SCORING CATEGORY]
RETURN
SWITCH(
TRUE(),
OccurrenceNumber = 4, "Moderate",
OccurrenceNumber = 5, "High",
OccurrenceNumber >= 6, "Critical",
OR(ISBLANK(ScoringCategory), ScoringCategory = ""), "IBT-" & OccurrenceNumber,
ScoringCategory
)
Would there be a way to prevent an occurence number from going backwards. Sorry, I think I worded that incorrectly. Essentially looking at this below, once an ID is "Critical" then that should be the last date populated. Meaning no date after that would be placed in one of the previous columns. So by order of events (IBT-1, IBT-2,IBT-3, Moderate, High, Critical) the dates should always run from oldest to newest in the table
What currently shows:
What should show:
Thank you again and for the quick response. That did it!
if field isblank
please elaborate. What field?
Your sample data is missing the Location, Status, NameType columns. Are these not important?
Note that Power Query is case sensitive. MODERATE is not the same as Moderate. (doesn't matter in DAX)
If field is blank or more stating that if that field, let's use IBT-1 for example, is blank. Essentially this is a stair step process meaning if you show up on this report the date for the row you show up on will go to IBT-1, then if you show up again you go to IBT-2, etc. The exception is if you have the result of "Moderate", "High", or "Critical" as a value under "Scoring Category" then you would skip all previous steps meaning they would result in "N/A".
The data points not provided (location, name, etc.) are not important for this example as my concern is more so around how to get the logic for the remaining fields.
Whoops, yep, sorry I wrote the example wrong but the actual format will match in prod.
Check out the October 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
117 | |
109 | |
106 | |
92 | |
68 |
User | Count |
---|---|
167 | |
130 | |
129 | |
95 | |
91 |