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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
gunicotra
Helper II
Helper II

Calculate with multiple conditions and with measure

Hi to everyone,

I am trying to calculate the count of some elements undependently from the slicer and using a measure for an index.

Basically I have:

- Year (slicer) = 2021

- [MonthUpDate] is a measure that gives the last Month of data collected.

 

I wouold like to have the count of elements for year 2018 and for the months March.

The solution I guessed is:

 

CALCULATE(sum('Table'[COUNTER]),
filter(all('Table'[YEAR]),'Table'[YEAR]=2018),
filter(all('Table'[DATA_IN]),month('Table'[DATA_IN])=[MonthUpDate]))

 

The formula is not wring, but I got no elements counted (i.e.: result = null) while in reality I have 14.500 elements in that year/month.

May enyone give some hints?

Thanks in advance

 

 

4 REPLIES 4
Anonymous
Not applicable

Hi @gunicotra ,

 

Can you give me some sample data and the results you want to get? Or share me with your pbix file from your Onedrive for Business.

 

You can create a calendar table and use the date column to create a date slicer to filter month and year.

 

Best Regards,

Stephen Tao

 

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

amitchandak
Super User
Super User

@gunicotra , if you have date. With help from date table

 

Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))

 

or

 

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-2,Year))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi amitchandak,

your first answer made me think at a different solution which worked well!

 

CALCULATE(sum('Table'[Counter]),
filter(all('Table'[YEAR]),'Table'[YEAR]=2018),
DATESINPERIOD('Table'[DATE_IN],[MinDatePY],-30,DAY)
)/4

 

With [MinDatePY] = DATE(2018,MONTH(NOW()),DAY(NOW())) is a new measure that brings back to 2018

 

Thus thank you for the hint 😉

Hi Kudos,

unfortunately this did not give the right solution. I still got no error, but "null" as value.

In order to provide more elements I can say that skipping the measure, give the right solution:

CALCULATE(sum('Table'[COUNTER]),
filter(all('Table'[YEAR]),'Table'[YEAR]=2018),
filter(all('Table'[DATA_IN]),month('Table'[DATA_IN])=3))

 

However in this case I just applicable to March.

 

I read that filtering with ALL( column).... should be the right answer to using a measure as index. But I don't understand whiy this is not working in my case.


Thanks

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.