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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
naejf
Regular Visitor

Create table with distinct count and sum of columns by month if its between 2 month dates

Hello,

 

I have a Table1 like this:

dayidaccountamountday + 60 days
14/09/2020111014/11/2020
15/09/2020212015/11/2020
17/09/202040017/11/2020
22/09/2020411022/11/2020
23/09/2020411023/11/2020
2/10/202021302/12/2020
3/10/202031203/12/2020
7/10/202051107/12/2020
12/11/2020511012/01/2021
13/11/2020112013/01/2021
19/11/2020213019/01/2021
24/11/2020312024/01/2021
26/11/2020602026/01/2021
15/12/2020612014/02/2021

The last column is only the first one + 60 days interval.

 

This table has a relationship with a Time Table created with autocalendar.

 

I would like create a Table 2 like this:

 

monthyeardistinct count idsum amount
1/09/2020350
1/10/20205110
1/11/20206210
1/12/19205180
1/01/20215120
1/02/2021120

 

Where I'd have a column with all monthyears in both 'day' column and 'day + 60 days' column of Table1; and for each monthyear , the disctinct count of Ids where monthyear of Table2 is between 'day' and 'day + 60 days', and the sum of amount where again monthyear of Table2 is between 'day' and 'day + 60 days'.

 

Thanks a lot for your help.

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@naejf , Try to create second table like

 

Table 2= Addcolumns(generateseries(1,15, 1), "Date",Date(2020, 8+[Value],1))

I doubt 1 sep between these dates

If required use end date

 

end Date = eomonth([Date], 0) 

 

And a new column = calculate(Distinctcount(Table1[ID]), filter(Table1[Day]<= Table2[Date] && Table1[Date] >= Table2[Date]))

 

Amount = calculate(sum(Table1[amount]), filter(Table1[Day]<= Table2[Date] && Table1[Date] >= Table2[Date]))

 

 

I doubt range logic is correct as per table given  above

 

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@naejf , Try to create second table like

 

Table 2= Addcolumns(generateseries(1,15, 1), "Date",Date(2020, 8+[Value],1))

I doubt 1 sep between these dates

If required use end date

 

end Date = eomonth([Date], 0) 

 

And a new column = calculate(Distinctcount(Table1[ID]), filter(Table1[Day]<= Table2[Date] && Table1[Date] >= Table2[Date]))

 

Amount = calculate(sum(Table1[amount]), filter(Table1[Day]<= Table2[Date] && Table1[Date] >= Table2[Date]))

 

 

I doubt range logic is correct as per table given  above

 

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hello @amitchandak,

 

Thanks for your help, your advice guided me to the logic of what I expected.

Only one question, Is there a way that Date column you created in Table2 could be created based in columns 'date' and 'date+60' of Table1 (like for example, min('date') and max('date'), or min('date') and max('date+60') )? I wonder this because the data I put is a sample of my real data, which update daily and months will increse, so I wouldn't like to have to change it manually.

Please, if you could give some advice with this last request, I'd really appreaciate.

 

@naejf , Try like

 

Table 2=

Var _diff = datediff(min(Table1[Day]), Max(Table1[End Date]),Month) // add +1 if needed

Var _st = min(Table1[Day])

return

Addcolumns(generateseries(1,_diff , 1), "Date",Date(year(_st), Month(_st)+[Value],1))

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak It did work! Thanks so much.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.