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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
jcastr02
Post Prodigy
Post Prodigy

calculating by distinct date

I am trying to add the totals from each store and then divide by the unique # of dates provided (as some stores will not have all the dates).  How could I achieve this in within Power Query?  I understand I would have to do some grouping by store number, but not sure how to do the calculation by theunique # of dates.  

Current  Desired
DateStore NumberTotals  Store NumberAvg Total by Unique # of Dates
1/1/20221815  1860 (***420/7***)
1/2/20221830  2042.5 (***170/4***)
1/3/20221845  3130.5 (***61/2***)
1/4/20221860    
1/5/20221870    
1/6/202218100    
1/7/202218100    
1/1/20222050    
1/2/20222050    
1/3/20222050    
1/4/20222020    
1/1/20223111    
1/2/20223150    
1 ACCEPTED SOLUTION
ronrsnfld
Super User
Super User

Change the Source line to reflect your actual data source:

let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Store Number", Int64.Type}, {"Totals", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Store Number"}, {
        {"Average Sales per Day", each List.Sum([Totals]) / List.Count(List.Distinct([Date])), type number}})
in
    #"Grouped Rows"

 

ronrsnfld_0-1717106389697.png

 

 

View solution in original post

1 REPLY 1
ronrsnfld
Super User
Super User

Change the Source line to reflect your actual data source:

let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Store Number", Int64.Type}, {"Totals", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Store Number"}, {
        {"Average Sales per Day", each List.Sum([Totals]) / List.Count(List.Distinct([Date])), type number}})
in
    #"Grouped Rows"

 

ronrsnfld_0-1717106389697.png

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.