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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jasonwq
Helper I
Helper I

Creating a new column filtered by date

I'm having an issue where I want to retrieve certain sales information by date, but I don't want to filter the entire visual by that date.

 

ITEMENTRY_TYPEQUANTITYDATE
ASALE1008/1/2021

A

SALE1007/1/2021

A

SALE1001/1/2015

B

SALE2001/1/2015

B

SALE2001/1/2010

 

In the above scenario, I want to to end up with the following report:

 

ITEMRECENT SALES (Last 6 months)
A200
B0

 

I have gotten it to work half-way using filters (Date Filter>Relative> 6 months), but then item B does not show up on the report because it does not have any rows that meet the criteria.

 

Thanks for your help!

1 ACCEPTED SOLUTION

Hi @jasonwq ,

You can create a measure as below:

RECENT SALES (Last 6 months) = 
CALCULATE (
    SUMX (
        'Table',
        IF (
            DATEDIFF ( 'Table'[DATE], TODAY (), MONTH ) < 6
                && DATEDIFF ( 'Table'[DATE], TODAY (), MONTH ) >= 0,
            'Table'[QUANTITY],
            0
        )
    )
)

yingyinr_0-1629713253825.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

5 REPLIES 5
Samarth_18
Community Champion
Community Champion

Hi @jasonwq ,

 

You can add one if condition at last like below:-

return if(result = 0,0,result)

It will help you get items which are not having sales in 6 months but they are present.

 

Thanks,

Samarth

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

I don't understand. Where do I put that code?

 

Could you please share your code which you have written, I will add this code into it accordingly

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Sorry, I don't have any code written. I've been using the Filters in PowerBI but this is not working well for me.

 

 

Hi @jasonwq ,

You can create a measure as below:

RECENT SALES (Last 6 months) = 
CALCULATE (
    SUMX (
        'Table',
        IF (
            DATEDIFF ( 'Table'[DATE], TODAY (), MONTH ) < 6
                && DATEDIFF ( 'Table'[DATE], TODAY (), MONTH ) >= 0,
            'Table'[QUANTITY],
            0
        )
    )
)

yingyinr_0-1629713253825.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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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