cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
KiranR
Frequent Visitor

Add new columns and count values from another table

Hi Guys,

This might be simple but struggling a bit hence need your support.

I have 2 different tables with dates; I want to create new columns in Table 1 and count the number of times the dates are repeated from Table 2 columns comparing to Table 1 rows. The third table in this query is the result I want.

Thanks in advance.

Table 1
Date
01-05-22
02-05-22
03-05-22
04-05-22
05-05-22
06-05-22
07-05-22
08-05-22
09-05-22
10-05-22

Table 2
Scheduled       Actual
01-05-22         01-05-22
01-05-22         02-05-22
02-05-22         02-05-22
02-05-22         02-05-22
02-05-22         02-05-22
02-05-22         02-05-22
02-05-22         02-05-22
03-05-22         03-05-22
04-05-22         04-05-22
04-05-22         04-05-22
04-05-22         04-05-22
04-05-22         05-05-22
04-05-22         05-05-22
04-05-22         05-05-22

Table 1
Date         Scheduled Count Actual Count
01-05-22                 2                   1
02-05-22                 5                   6
03-05-22                 1                   1
04-05-22                 6                   3
05-05-22                 0                   3
06-05-22                 0                   0
07-05-22                 0                   0
08-05-22                 0                   0
09-05-22                 0                   0
10-05-22                 0                   0

 

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@KiranR , a new column in table one

 

Scheduled = countx(filter(Table2, Table1[Date] = Table2[Scheduled]) ,Table2[Scheduled])

 

Actual= countx(filter(Table2, Table1[Date] = Table2[Actual]) ,Table2[Actual])



Power BI Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s || 50+Power Query List Functions : Learn Power Query List
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!
Want To Learn Power BI | Beginners !! Advance Concepts !! Power BI For Tableau User !!

View solution in original post

3 REPLIES 3
Aditya_Meshram
Super User
Super User

Hi @KiranR ,
in case you want a separate table and want 0's instead of NULL values in your table, you can use this DAX

 

 

Table 3 = 
ADDCOLUMNS(
    'Table 1',
    "Actual Count",COALESCE(COUNTX(FILTER('Table 2','Table 1'[Date] = 'Table 2'[Actual]),'Table 2'[Actual]),0),
    "Scheduled Count",COALESCE(COUNTX(FILTER('Table 2', 'Table 1'[Date] = 'Table 2'[Scheduled]) ,'Table 2'[Scheduled]),0)
)

 

 

Aditya_Meshram_0-1652092913330.png

 

 

Regards

CNENFRNL
Super User
Super User

CNENFRNL_0-1652091684206.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is beyond their comprehension!

DAX is simple, but NOT EASY!

amitchandak
Super User
Super User

@KiranR , a new column in table one

 

Scheduled = countx(filter(Table2, Table1[Date] = Table2[Scheduled]) ,Table2[Scheduled])

 

Actual= countx(filter(Table2, Table1[Date] = Table2[Actual]) ,Table2[Actual])



Power BI Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s || 50+Power Query List Functions : Learn Power Query List
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!
Want To Learn Power BI | Beginners !! Advance Concepts !! Power BI For Tableau User !!

Helpful resources

Announcements
September Update

Check it Out!

Click here to learn more about the September 2022 updates!

Power BI Show episode 9

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 25

Ted's Dev Camp - August 25, 2022

Watch Session 25 of Ted's Dev Camp.

Top Solution Authors