cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sovereignauto
Helper I
Helper I

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.

View solution in original post

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
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Top Solution Authors
Top Kudoed Authors