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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
kalspiros
Helper I
Helper I

Calculate with slicer date

Hi all,

 

I'm sorry, i'm sure the answer has been addressed again but from some quick search, i couldn't find it 😕

And TOTALYTD doesn't seem to do the trick for me.

So:

kalspiros_1-1643717170094.png

I'm trying to capture the sum of all [days] an employee was off sick from the beginning of the year until the slicer date.

 

Slicer Month:= CALCULATE(MIN('Leaves'[Month]))

CSP so far this year:= CALCULATE(SUMX('Leaves',IF('Leaves'[Month]<=[Slicer Month],[days],0)),ALL('Leaves'[Month Name]))

i've also tried

CSP so far this year:= CALCULATE(SUM([days]), ALL('Leaves'[Month Name]),FILTER('Leaves','Leaves'[Month]<=[Slicer Month]))

 

None of them returns the correct value.

I'm so confident the answer would be a "d-uh"! moment for me so apologies for my ignorance!

 

Many thanks in advance

1 ACCEPTED SOLUTION
ValtteriN
Super User
Super User

Hi,

Here is one way to do this:

RT month =
var _year = YEAR(MAX(Aggregation[Opened At]))
var _month = MONTH(MAX(Aggregation[Opened At (Month)]))
return

CALCULATE(SUM(Aggregation[Duration(Secs)]),ALL(Aggregation),MONTH(Aggregation[Opened At (Month)])<=_month,YEAR(Aggregation[Opened At (Month)]=_year))

ValtteriN_0-1643721429104.png

 

The example is a bit different but the base logic is the same. Ping me with @ if you have questions about it.I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/
 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
ValtteriN
Super User
Super User

Hi,

Here is one way to do this:

RT month =
var _year = YEAR(MAX(Aggregation[Opened At]))
var _month = MONTH(MAX(Aggregation[Opened At (Month)]))
return

CALCULATE(SUM(Aggregation[Duration(Secs)]),ALL(Aggregation),MONTH(Aggregation[Opened At (Month)])<=_month,YEAR(Aggregation[Opened At (Month)]=_year))

ValtteriN_0-1643721429104.png

 

The example is a bit different but the base logic is the same. Ping me with @ if you have questions about it.I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/
 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@ValtteriN that works perfect! many thanks! interested on your opinion, why my second measure above didn't work? The [Month] is just the number of the month, so is the slicer. Kind of happy to see that i wasn't miles away 😄 

Thank you once again!

@kalspiros  The key difference is that you used FILTER. FILTER creates a table filtered with the conditions while using filter conditions in CALCULATE modify the filter context.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors