cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Anonymous
Not applicable

Calculate with filter and date

Hello guys, I need your help! Trying to do this all the week!

 

I want a formula like that:

 

Column 2 = calculate(COUNTAX(Planilha1;Planilha1[REQMAT]);filter(Planilha1;Planilha1[REQMAT]=EARLIER(Planilha1[REQMAT])&&Planilha1[dia]=DATEADD(Planilha1[dia];-1;DAY)))

 

I tried this but I get all Blank, I don't know how can I filter date - 1.

Need help, please

5 REPLIES 5
Highlighted
Community Support
Community Support

Re: Calculate with filter and date

HI, @Anonymous

You could try to use this formula:

Column 2 = 
CALCULATE (
    COUNTAX ( Planilha1, Planilha1[REQMAT] ),
    FILTER (
        Planilha1,
        Planilha1[REQMAT] = EARLIER ( Planilha1[REQMAT] )
            && DATEDIFF(Planilha1[dia],EARLIER(Planilha1[dia]),DAY)=1
    )
)

Result:

1.JPG

 

Best Regards,

Lin

 

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

Re: Calculate with filter and date

It worked, although my dates are the week day, monday to friday, and when it gets to monday the result is incorrect, i am not sure yet why, but i think it's calculating considering sunday, and not friday.

 

Capturar.PNG

Highlighted
Community Support
Community Support

Re: Calculate with filter and date

hi, @Anonymous

For your requirement, you could use WEEKDAY Function to add a conditional in the formula like this:

Column 3 = IF(WEEKDAY(Planilha1[dia],2)=1,CALCULATE (
    COUNTAX ( Planilha1, Planilha1[REQMAT] ),
    FILTER (
        Planilha1,
        Planilha1[REQMAT] = EARLIER ( Planilha1[REQMAT] )
            && DATEDIFF(Planilha1[dia],EARLIER(Planilha1[dia]),DAY)=3
    )
),CALCULATE (
    COUNTAX ( Planilha1, Planilha1[REQMAT] ),
    FILTER (
        Planilha1,
        Planilha1[REQMAT] = EARLIER ( Planilha1[REQMAT] )
            && DATEDIFF(Planilha1[dia],EARLIER(Planilha1[dia]),DAY)=1
    )
))

Best Regards,

Lin

 

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

Re: Calculate with filter and date

Thanks, I managed to do that but worked for a while.

 

And what if I have holidays and I never know how many days are going to be off.

 

I need someway to calculate a date difference using a serial number as filter.

 

Capturar.PNG

In my example in this pic, for example, I need a way to calculate the date differente of the first serial number "688819", and it needs to be variable, is not always going to be the same number.

Highlighted
Community Support
Community Support

Re: Calculate with filter and date

hi, @Anonymous

First, you should know that difference between calculated column and calculate measure 

Notice:

1. Calculation column/table not support dynamic changed based on filter or slicer.
2. measure can be affected by filter/slicer, so you can use it to get dynamic summary result.

here is reference:

https://community.powerbi.com/t5/Desktop/Different-between-calculated-column-and-measure-Using-SUM/t...

https://www.sqlbi.com/articles/calculated-columns-and-measures-in-dax/

Second, If you have holidays, you need to have a work calendar first, then add an index for work date, then use it for calculating a date difference.

And you'd better share us sample pbix file or some data sample and expected output. You can upload it to OneDrive and post the link here. Do mask sensitive data before uploading, That will be a better understanding of your requirement then screenshot.

 

 

 

Best Regards,

Lin

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

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Upcoming Events

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors
Users online (859)