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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
pani_victoria
Helper III
Helper III

sales by date and by month in one measure

Hello!

I have sales by product and a slicer by date "BEFORE".
The result I want to get in one measure is:
- if no date is selected in the slicer, then sales for the month (MTD)
- if a date is selected in the slicer, then sales for that date.
Is this possible and how?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks solution from @vicky_ , your solution is great!

Hi, @pani_victoria 

Based on your description, I have created the following sample data:

vjianpengmsft_0-1713855262820.png

I have the following two measures:

vjianpengmsft_1-1713855311063.png

vjianpengmsft_2-1713855371031.png

I created a date table using the following DAX expression:

Table 2 = CALENDAR(MIN('Table'[Date]),TODAY())

I'm using columns from the entire date table in the slicer:

vjianpengmsft_3-1713855476101.png

I use the following DAX expression to create a measure that switches the MTD to the current day's breakdown:

sales =
VAR _seleteddate =
    SELECTEDVALUE ( 'Table 2'[Date] )
RETURN
    IF (
        ISBLANK ( _seleteddate ),
        [Sales MTD],
        CALCULATE ( [Sales amount], 'Table'[Date] = _seleteddate )
    )

Here are the results:

When the date slicer is not checked, the MTD is displayed:

vjianpengmsft_4-1713855671123.png

If the date is selected, the details of the current day are displayed:

vjianpengmsft_5-1713855742436.png

I've provided the PBIX file used this time below.

 

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thanks solution from @vicky_ , your solution is great!

Hi, @pani_victoria 

Based on your description, I have created the following sample data:

vjianpengmsft_0-1713855262820.png

I have the following two measures:

vjianpengmsft_1-1713855311063.png

vjianpengmsft_2-1713855371031.png

I created a date table using the following DAX expression:

Table 2 = CALENDAR(MIN('Table'[Date]),TODAY())

I'm using columns from the entire date table in the slicer:

vjianpengmsft_3-1713855476101.png

I use the following DAX expression to create a measure that switches the MTD to the current day's breakdown:

sales =
VAR _seleteddate =
    SELECTEDVALUE ( 'Table 2'[Date] )
RETURN
    IF (
        ISBLANK ( _seleteddate ),
        [Sales MTD],
        CALCULATE ( [Sales amount], 'Table'[Date] = _seleteddate )
    )

Here are the results:

When the date slicer is not checked, the MTD is displayed:

vjianpengmsft_4-1713855671123.png

If the date is selected, the details of the current day are displayed:

vjianpengmsft_5-1713855742436.png

I've provided the PBIX file used this time below.

 

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

vicky_
Super User
Super User

From the wording, I assume that you have a single-date slicer.
If so, then you can try wrap your calculations in an if statement. Something like:

Your Measure = IF(HASONEVALUE('Slicer Table'[Date]), 
    // ... your calculations for sales
    , // your calculations for MTD
)

 

Helpful resources

Announcements
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.