Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Iterate through multiple columns to produce a value

I am trying to write a method in Power BI to select the last date in a column but iterates through other columns and then counts the number of occurences of that time stamp.

 

Provided below is an example. I have a table of hundreds of employees and every employee has several skills that can be in different status of completion and a time log of each time the status changes. When the status changes, the previous status keeps it time stamp and new value is created for the new status. With a slicer for Status, I want to have a card that shows the count of the last date over a time range, which a time slicer would be used to change the range. From the example below, if the slicer was selected as Status = Not Verified, the card should display 2. That is because it is only selecting the skills for each employee where Not Verified is the last time stamp. I highlighted those two values in red text show which two I am referring to. 

 

In other words, for every employee and each of their skills, count the last status for that skill. The Date/Time column seems to be the log of the most current status of that skill. I was researching how to apply a for loop for this but I could not figure that out with DAX.

 

Example table:

Employee NameSkill NameStatusDate/Time
Employee 1CodingNot Verified2/23/23 10:00:00
Employee 1CodingSubmitted2/23/23 10:30:00
Employee 1WritingNot Verified2/23/23 10:00:00
Employee 2CodingNot Verified2/23/23 10:00:00
Employee 2CodingSubmitted2/23/23 10:15:00
Employee 2 CodingVerified2/23/23 11:00:00
Employee 3CommunicationNot Verified2/23/23 12:00:00
1 ACCEPTED SOLUTION

@Anonymous 

Do you mean like this?

2.png1.png

Skill Count = 
CALCULATE ( 
    SUMX ( 
        SUMMARIZE ( 'Table', 'Table'[Employee Name], 'Table'[Skill Name], 'Table'[Status] ),
        IF ( 
            CALCULATE ( MAX ( 'Table'[Date/Time] ) ) =
                CALCULATE ( MAX ( 'Table'[Date/Time] ), ALL ( 'Table'[Date/Time], 'Table'[Status] ), ALL ( 'Status' ) ),
            1
        )
    ),
    'Date'[Date] <= MAX ( 'Date'[Date] )
)

 

View solution in original post

16 REPLIES 16
tamerj1
Super User
Super User

Hi @Anonymous 
Please provide more examples

Anonymous
Not applicable

In the table below Employee 1 has 11 unique Skill Names, which you can see has multiple Status per Skill Name and some have repeated values from changing of those statuses. With a slicer selected as Status = Not Verified, the total should show 7 by returning back 1 Status with the Status as Not Verified per Skill Name. Because that Status can be multiple times per Skill Name, the latest Date/Time should be selected. 

 

Employee NameSkill NameStatusDate/Time
Employee 1InterpersonalNot verified8/21/19 12:17
Employee 1InterpersonalNot verified8/21/19 12:17
Employee 1InterpersonalNot verified8/21/19 12:17
Employee 1Adaptability & FlexibilityVerified8/21/19 12:20
Employee 1Managing WorkVerified8/21/19 12:20
Employee 1Senior / Lead Claim Processing TechnicianNot verified8/21/19 12:20
Employee 1Adaptability & FlexibilitySubmitted8/22/19 17:12
Employee 1Quality OrientationNot verified9/24/19 20:27
Employee 1Initiating ActionSubmitted9/24/19 20:27
Employee 1Quality OrientationSubmitted9/24/19 20:27
Employee 1System ArchitectureSubmitted9/24/19 20:27
Employee 2Quality OrientationSubmitted9/24/19 20:28
Employee 2Senior / Lead Claim Processing TechnicianSubmitted9/24/19 20:28
Employee 2System ArchitectureSubmitted9/24/19 20:28
Employee 1System ArchitectureVerified10/14/19 19:18
Employee 1Quality OrientationNot verified10/14/19 19:18
Employee 1Senior / Lead Claim Processing TechnicianSubmitted10/15/19 1:39
Employee 3Quality OrientationNot verified10/16/19 16:21
Employee 3System ArchitectureVerified10/16/19 16:21
Employee 1Active ListeningNot verified10/17/19 22:34
Employee 1ResponsibleNot verified10/17/19 22:34
Employee 1Stress ToleranceNot verified10/17/19 22:34
Employee 1High School Diploma or equivalentNot verified10/23/19 19:21
Employee 4InfrastructureSubmitted11/14/19 17:35
Employee 4Presenting & Communicating InformationSubmitted11/14/19 17:35

 

Here is the same table but with only Employee 1 and sorted by Skill Name then Date/Time to more easily understand the example above. The table above was sorted by Date/Time as it would normally appear.

Employee NameSkill NameStatusDate/Time
Employee 1Active ListeningNot verified10/17/19 22:34
Employee 1Adaptability & FlexibilitySubmitted8/22/19 17:12
Employee 1Adaptability & FlexibilityVerified8/21/19 12:20
Employee 1High School Diploma or equivalentNot verified10/23/19 19:21
Employee 1Initiating ActionSubmitted9/24/19 20:27
Employee 1InterpersonalNot verified8/21/19 12:17
Employee 1InterpersonalNot verified8/21/19 12:17
Employee 1InterpersonalNot verified8/21/19 12:17
Employee 1Managing WorkVerified8/21/19 12:20
Employee 1Quality OrientationNot verified10/14/19 19:18
Employee 1Quality OrientationSubmitted9/24/19 20:27
Employee 1Quality OrientationNot verified9/24/19 20:27
Employee 1ResponsibleNot verified10/17/19 22:34
Employee 1Senior / Lead Claim Processing TechnicianSubmitted10/15/19 1:39
Employee 1Senior / Lead Claim Processing TechnicianNot verified8/21/19 12:20
Employee 1Stress ToleranceNot verified10/17/19 22:34
Employee 1System ArchitectureVerified10/14/19 19:18
Employee 1System ArchitectureSubmitted9/24/19 20:27

@Anonymous 
Ok, that does not match with your initial description. Kindly provide your red markups on below proposal's screenshots.

1.png2.png

Anonymous
Not applicable

In your two examples, the total should be the sum of all employees for that status.

Example 1:

Employee 1 = 7 + Employee 3 = 1 == Total = 8

Example 2: 

Employee 1 = 5 + Employee 2 = 3 + Employee 4 = 2 == Total = 10

 

In addition in your first table, you can see that for the skill Quality Orientation you are returning two values for Not Verified. There are two values of Not Verified for that Skill but I only need the latest status and only counting that 1.

 

In the example that I provided for Employee 1, I've highlighted below the skills that should be counted for Not Verified:

Employee NameSkill NameStatusDate/Time
Employee 1Active ListeningNot verified10/17/19 22:34
Employee 1Adaptability & FlexibilityVerified8/21/19 12:20
Employee 1Adaptability & FlexibilitySubmitted8/22/19 17:12
Employee 1High School Diploma or equivalentNot verified10/23/19 19:21
Employee 1Initiating ActionSubmitted9/24/19 20:27
Employee 1InterpersonalNot verified8/21/19 12:17
Employee 1InterpersonalNot verified8/21/19 12:17
Employee 1InterpersonalNot verified8/21/19 12:17
Employee 1Managing WorkVerified8/21/19 12:20
Employee 1Quality OrientationNot verified9/24/19 20:27
Employee 1Quality OrientationSubmitted9/24/19 20:27
Employee 1Quality OrientationNot verified10/14/19 19:18
Employee 1ResponsibleNot verified10/17/19 22:34
Employee 1Senior / Lead Claim Processing TechnicianNot verified8/21/19 12:20
Employee 1Senior / Lead Claim Processing TechnicianSubmitted10/15/19 1:39
Employee 1Stress ToleranceNot verified10/17/19 22:34
Employee 1System ArchitectureSubmitted9/24/19 20:27
Employee 1System ArchitectureVerified10/14/19 19:18

I also made an error before, the total for Not Verified should be 6. I counted an extra one because I had the dates sorted the wrong way. The most recent status needs to be Not Verified for it to count. You will notice the Skill Senior / Lead Claim Processing Technician is not counted now.

Anonymous
Not applicable

@tamerj1 checking to see if you saw my response.

@Anonymous 
Sorry, I did not notice. Please refer to attached sample file.

1.png

2.png

Skill Count = 
SUMX ( 
    SUMMARIZE ( 'Table', 'Table'[Employee Name], 'Table'[Skill Name], 'Table'[Status] ),
    IF ( 
        CALCULATE ( MAX ( 'Table'[Date/Time] ) ) =
            CALCULATE ( MAX ( 'Table'[Date/Time] ), ALL ( 'Table'[Date/Time] ) ),
        1
    )
)
Anonymous
Not applicable

@tamerj1 Thank you for your quick response. The values for the Not Verified are not accurate. Please see the last post I shared with values in red.

"I also made an error before, the total for Not Verified should be 6. I counted an extra one because I had the dates sorted the wrong way. The most recent status needs to be Not Verified for it to count. You will notice the Skill Senior / Lead Claim Processing Technician is not counted now."

 

Based on your method, it would somehow be Max date but for a given skill. Since this is a continuous log based on skill status, the skill will be repeated for every updated skill status, and thats why I need the last time for that skill = that is the current status of the skill. 

@Anonymous 
This would require a status dim table. Please refer to attached sample file

1.png2.png

Skill Count = 
SUMX ( 
    SUMMARIZE ( 'Table', 'Table'[Employee Name], 'Table'[Skill Name], 'Table'[Status] ),
    IF ( 
        CALCULATE ( MAX ( 'Table'[Date/Time] ) ) =
            CALCULATE ( MAX ( 'Table'[Date/Time] ), ALL ( 'Table'[Date/Time], 'Table'[Status] ), ALL ( 'Status' ) ),
        1
    )
)
Anonymous
Not applicable

Thank you @tamerj1 . This was very helpful. I am a little unsure as to why a separate dim table would be required.

If I wanted to modify this measure to filter the skill status as Not verified, how could this be update? The ALL function is throwing me off, which is intended to clear all filters.

 

I want to create a measure for each skill status and plot that data across a line chart, showcasing the different status changing over time. 

@Anonymous 

Do you mean like this?

2.png1.png

Skill Count = 
CALCULATE ( 
    SUMX ( 
        SUMMARIZE ( 'Table', 'Table'[Employee Name], 'Table'[Skill Name], 'Table'[Status] ),
        IF ( 
            CALCULATE ( MAX ( 'Table'[Date/Time] ) ) =
                CALCULATE ( MAX ( 'Table'[Date/Time] ), ALL ( 'Table'[Date/Time], 'Table'[Status] ), ALL ( 'Status' ) ),
            1
        )
    ),
    'Date'[Date] <= MAX ( 'Date'[Date] )
)

 

Anonymous
Not applicable

@tamerj1 This looks good, but I am confused about the additional dim tables. Why would I need both the date and status tables if those values are already within the table with Employee Name and Skill Status?

@Anonymous 

It could work. Actually I tried a solution myself without dim and it worked to some extent. This is related to the dax engine optimization properties that makes the utilization of dim tables easier to obtain the required results. Long story short try to rely more on dim tables in your data models. 

Anonymous
Not applicable

Thank you! One last question, if I wanted to take the values that are calculated for the skill count measure and display the totals for each skill status is separate cards, is there a way to filter those out individually? The result would look like this below (those values are incorrect and are simply countrows for the skill status, but thats how I am trying to display the correct skill count values).

Screen Shot 2023-02-28 at 10.53.44 AM.png

@Anonymous 

Try 

Skill Count Submitted =
CALCULATE ( [Skill Count], Status[Status] = "Submitted" )

Anonymous
Not applicable

The sum of each card (with the measure above) is totaling the sum of all status together, which checks out. However in the line chart when I count the value for each month, it is much greater.

 

The card all the way to the right is the total of the 3 other cards. Counting the values in the tooltip across each month, the values shown for Verified (and the others) is greater than what is displaying in the cards. All of these should match. Any idea why it is not? 

Screen Shot 2023-02-28 at 12.24.33 PM.png

Anonymous
Not applicable

@tamerj1 I tested this a bit further and the reason is that the Cards are not being updated with the Date slicer whereas the line chart is. The Cards should be changing as the date changes.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.