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

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

Reply
Anonymous
Not applicable

Calculate sales (sum of a column) based on the date selected using filter.

ann_2024_1-1704968759036.png

 

I am having a date filter like shown above where the user can select a year (where all months of the year gets selected) or the user can select a specific month (and all days of the month gets selected) or select a specific day. If the user selects a year, the total sales of the entire year is to calculated. If the user selects a month, need to calculate sales of the month only and if the user selects a day, MTD sales is to be calculated. Any ideas for a DAX function to handle this?

1 ACCEPTED SOLUTION

hi, @Anonymous 

 

try below measure and see below image it might help

 

Measure 2 = 
var a  = HASONEFILTER('Calendar'[Date].[Day])
return
IF(a,CALCULATE([Quantity],DATESMTD('Calendar'[Date])),[Quantity])

 

for month selection

Dangar332_0-1705339213151.png

 

for day selection

Dangar332_1-1705339299190.png

 

 

View solution in original post

5 REPLIES 5
Dangar332
Super User
Super User

hi, @Anonymous 

 

try below measure

measure =
if(
  isinscope(datetable[day column]),
  calculate(
    sum(tablename[sales]),
    removefilters(),
    values(datetable[day column]),
    datesmtd(datetable[day column])
  ),
 sum(tablename[sales])
) 
Anonymous
Not applicable

Hi @Dangar332,
Thanks for your response. When I tried the measure you provided, its returning an error - 

A column specified in the call to function 'DATESMTD'  is not of type DATE. 
So I tried the Date column (and not day coumn), the else part was working fine but the if part is returning the daywise sales and not MTD. 

 

 

measure = 
if(
  isinscope('Date Master'[Day]),
  calculate(
    [Sales Value],
    removefilters(),
    values('Date Master'[Day]),
    datesmtd('Date Master'[Date])
  ),
 [Sales Value])

 

 

 

My Date Master has columns:

  1. Date
  2. Day - (Measure= DAY('Date Master'[Date])
  3. Month -
  4. Year -

    I have used Year, Month and Day as fields in slicer.  

hi, @Anonymous 

remove 

values('Date Master'[Day])

 

from code

Anonymous
Not applicable

Hi @Dangar332 

Still the problem persist. Ay other ideas to solve the problem?

hi, @Anonymous 

 

try below measure and see below image it might help

 

Measure 2 = 
var a  = HASONEFILTER('Calendar'[Date].[Day])
return
IF(a,CALCULATE([Quantity],DATESMTD('Calendar'[Date])),[Quantity])

 

for month selection

Dangar332_0-1705339213151.png

 

for day selection

Dangar332_1-1705339299190.png

 

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.