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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

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

 

 

Share with Power BI Enthusiasts: 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

 

 

Share with Power BI Enthusiasts: 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))

Share with Power BI Enthusiasts: 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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.