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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
FredCarmoSilva
New Member

SQL Windowed function in DAX

Hi all,

 

I am finding quite hard to get to grips with the different contexts in PBI and creating some "windowed functions". Hopefully the resolution to this problem will push me closer to being proficient in PBI.

 

I have something like the Data below, where the months shown come from a Slicer (Last 3 Months(Calendar) for example.

I can calculate the coloured cells, but am struggling to aggreagate the apples sold by each store on the months shown (as per the Count apples sold selected months column).

 

Please note that Count apples sold is actually a Count of transactions, it is effectively a DISTINCTCOUNT(TransactionID).

 

Any help would be greatly appreciated.

Regards,

Fred

 

Capture.PNG

1 ACCEPTED SOLUTION

For anyone who might be looking for a solution, this ended up being quite simple. 

Given that I had a Date[TransactionDate] as a Slicer, and the Month show on the table was Date[TransactionMonth] what I was doing wrong was trying to get ALLSELECTED( Date[TransactionMonth]  ) and should have done ALLSELECTED( Date ). 

 

Solution was to do :

 

Number of Transactions per Store on Shown Months = CALCULATE(DISTINCTCOUNT(TransactionID), ALLSELECTED( Date ))

View solution in original post

3 REPLIES 3
Tahreem24
Super User
Super User

 @FredCarmoSilva ,

 

Please create a below measure and check you result:

Count Apple sold each month = CALCULATE(Sum('Table'[Count Apple Sold]),ALLEXCEPT('Table','Table'[Store Name]))

 

Please give KUDOS and accept this as a solution if it helps you!

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

@Tahreem24 

 

Thanks for your answer.

It didn't do what I was looking for though, what happened with what you suggested is that now I have some Stores that appeared although they didn't have any transcation on the 3 months shown on the table.

 

I will try to add more info so you can get a better idea of what I am working with.

 

Maybe think of Count apples sold as being Count of transactions because effectively that is what it is, is a Measure doing a DISTINCTCOUNT('Table'[Transaction_ID]).

My months are coming from a Slicer, so effectively that are more many months of data, but I am Slicing/Filtering to 3 months only.

 

 

For anyone who might be looking for a solution, this ended up being quite simple. 

Given that I had a Date[TransactionDate] as a Slicer, and the Month show on the table was Date[TransactionMonth] what I was doing wrong was trying to get ALLSELECTED( Date[TransactionMonth]  ) and should have done ALLSELECTED( Date ). 

 

Solution was to do :

 

Number of Transactions per Store on Shown Months = CALCULATE(DISTINCTCOUNT(TransactionID), ALLSELECTED( Date ))

Helpful resources

Announcements
Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

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.