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
sovereignauto
Helper III
Helper III

foreach on a table to monitor interactions

Good Morning, 

i have two tables thats contain between them three dates and three name fields (as well as loads of other fields) as per the below:

 

Table1 

[taskdate1] [name1] [taskdate2] [name2] 

 

Table2 

[taskdate3][name3]


What i need to do is in this month count how many days a user has done at least one of the above tasks.

i have a custom table with a list of user names and what i feel like i need to do is the below:

 

for each date MTD as date 

_var "count" = 0 

foreach row in the table if taskdate1 is date and name = username then "count" +1 end
foreach row in the table if taskdate2 is date and name = username then "count" +1  end

foreach row in the table if taskdate3 is date and name = username then "count" +1  end

if count is > 1 then "days interacted" + 1 

Hope thats makes some sense and someone may be able to help me

1 ACCEPTED SOLUTION
v-kkf-msft
Community Support
Community Support

Hi @sovereignauto ,

 

Try the following formula:

_Count = 
var Year = SELECTEDVALUE('Date'[Date].[Year])
var Month = SELECTEDVALUE('Date'[Date].[Month])
var tab1 = SUMMARIZE('Table1', 'Table1'[taskdate1].[Year], 'Table1'[taskdate1].[Month], Table1[name1])
var tab2 = SUMMARIZE('Table1', 'Table1'[taskdate2].[Year], 'Table1'[taskdate2].[Month], Table1[name2])
var tab3 = SUMMARIZE('Table2', 'Table2'[taskdate3].[Year], 'Table2'[taskdate3].[Month], Table2[name3])
var task1 = 
    CALCULATE(
        COUNT(Table1[name1]),
        FILTER(tab1,Table1[name1] = MAX(Users[name]) && Table1[taskdate1].[Year]=Year && Table1[taskdate1].[Month]=Month)
    )
var task2 = 
    CALCULATE(
        COUNT(Table1[name2]),
        FILTER(tab2,Table1[name2] = MAX(Users[name]) && Table1[taskdate2].[Year]=Year && Table1[taskdate2].[Month]=Month)
    )
var task3 = 
    CALCULATE(
        COUNT(Table2[name3]),
        FILTER(tab3,Table2[name3] = MAX(Users[name]) && Table2[taskdate3].[Year]=Year && Table2[taskdate3].[Month]=Month)
    )
return task1 + task2 + task3
day interacted = 
CALCULATE(
    COUNT(Users[name]),
    FILTER(Users, [_Count] > 1)
)

image.pngimage.png

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-kkf-msft
Community Support
Community Support

Hi @sovereignauto ,

 

Try the following formula:

_Count = 
var Year = SELECTEDVALUE('Date'[Date].[Year])
var Month = SELECTEDVALUE('Date'[Date].[Month])
var tab1 = SUMMARIZE('Table1', 'Table1'[taskdate1].[Year], 'Table1'[taskdate1].[Month], Table1[name1])
var tab2 = SUMMARIZE('Table1', 'Table1'[taskdate2].[Year], 'Table1'[taskdate2].[Month], Table1[name2])
var tab3 = SUMMARIZE('Table2', 'Table2'[taskdate3].[Year], 'Table2'[taskdate3].[Month], Table2[name3])
var task1 = 
    CALCULATE(
        COUNT(Table1[name1]),
        FILTER(tab1,Table1[name1] = MAX(Users[name]) && Table1[taskdate1].[Year]=Year && Table1[taskdate1].[Month]=Month)
    )
var task2 = 
    CALCULATE(
        COUNT(Table1[name2]),
        FILTER(tab2,Table1[name2] = MAX(Users[name]) && Table1[taskdate2].[Year]=Year && Table1[taskdate2].[Month]=Month)
    )
var task3 = 
    CALCULATE(
        COUNT(Table2[name3]),
        FILTER(tab3,Table2[name3] = MAX(Users[name]) && Table2[taskdate3].[Year]=Year && Table2[taskdate3].[Month]=Month)
    )
return task1 + task2 + task3
day interacted = 
CALCULATE(
    COUNT(Users[name]),
    FILTER(Users, [_Count] > 1)
)

image.pngimage.png

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

thats great thank you!

I ended up doing it in a very similar way but managed to redue it down to only one task so created a summary table to work from. 

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.