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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Lilliua
New Member

DAX measure - two value types - two date ranges

Hi all!

I have two tables that i need to work on: Orders and Calender.

The Orders table has following columns: Product (text), Quantity (number), OrderDate (date), Price (number), Seller (text), Discounts (number).

*The Product column has three values: Red, Blue, Yellow.

The Calender table has following columns: Date (whole date format), Month, MonthName, Quarter, Year, DayofMonth.

* The date range is 01.01.2015-05.31.2019.

I have already a measure for:

- [TotalSales]

- [Red] = CALCULATE ([TotalSales], FILTER ('Orders', 'Orders' [Product]="Red"))

- same as above for Blue and Yellow

 

I need to create a visual with a column chart that will show at the same time:

- All data for Red from the start date till 30.04.2017

- All data for Blue from 01.05.2018 till end date

 

So i need to filter a column in a table by a text value (red/blue) and filter it then by a given date range. I was trying to use DATESBETWEEN, but as I am new to this I guess I miss something here. I tried to do it for Red and Blue separately first:

 

Red = CALCULATE((Orders[Product]="Red")),  DATESBETWEEN(Calender[Date], DATE(01.01.2015), DATE(30.04.2017)).

 

Could you help out here? Would appreciate it much, thanks.

 

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @Lilliua ,

You can create a measure as below to get it, please find the details in the attachment.

Measure = 
VAR _product =
    SELECTEDVALUE ( 'Orders'[Product] )
RETURN
    SWITCH (
        _product,
        "Red",
            SUMX (
                FILTER (
                    'Orders',
                    'Orders'[OrderDate] >= DATE ( 2015, 1, 1 )
                        && 'Orders'[OrderDate] <= DATE ( 2017, 4, 30 )
                ),
                [TotalSales]
            ),
        "Blue",
            SUMX (
                FILTER (
                    'Orders',
                    'Orders'[OrderDate] >= DATE ( 2018, 5, 1 )
                        && 'Orders'[OrderDate] <= DATE ( 2019, 5, 31 )
                ),
                [TotalSales]
            )
    )

vyiruanmsft_0-1718330360064.png

Best Regards

Community Support Team _ Rena
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

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

Hi @Lilliua ,

You can create a measure as below to get it, please find the details in the attachment.

Measure = 
VAR _product =
    SELECTEDVALUE ( 'Orders'[Product] )
RETURN
    SWITCH (
        _product,
        "Red",
            SUMX (
                FILTER (
                    'Orders',
                    'Orders'[OrderDate] >= DATE ( 2015, 1, 1 )
                        && 'Orders'[OrderDate] <= DATE ( 2017, 4, 30 )
                ),
                [TotalSales]
            ),
        "Blue",
            SUMX (
                FILTER (
                    'Orders',
                    'Orders'[OrderDate] >= DATE ( 2018, 5, 1 )
                        && 'Orders'[OrderDate] <= DATE ( 2019, 5, 31 )
                ),
                [TotalSales]
            )
    )

vyiruanmsft_0-1718330360064.png

Best Regards

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

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

July Newsletter

Fabric Community Update - July 2024

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

Top Solution Authors