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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
danakajoel
Frequent Visitor

Conditional aggregation / filter

Hi, newbie post here. I have a dataset of month end stock values over time, i.e. [Stock ID, Month End Date, Stock Value]

 

I also have a dataset of income received from these stocks over time, i.e. [Stock ID, Month End Date, Income Received]

 

The model is built with date table and various other look up tables.

 

It's a large dataset but it appears that in some instances, we've not reconciled the income in our system so we have stock values but no associated income.

 

I'm trying to create a filter which shows me where we have postive stock values but haven't reconciled any income in the past 6 months. I'm sure it's straightforward but I'm drawing a blank 😞

 

TIA

1 ACCEPTED SOLUTION

Hi @danakajoel ,

First create 4 columns in both tables:

 

 

Frequency = LOOKUPVALUE('Plan Lookup'[Column2],'Plan Lookup'[Column1],'Income Receipts'[Plan Number],Blank())
YEAR = YEAR('Income Receipts'[Period End Date])
Month = MONTH('Income Receipts'[Period End Date])
Quarter = QUARTER('Income Receipts'[Period End Date])

 

 

Then create a total column in both tables:

 

 

_Total = SWITCH('Income Receipts'[Frequency],
"Ad-Hoc",CALCULATE(SUM('Income Receipts'[Income Received])),
"Quarterly",CALCULATE(SUM('Income Receipts'[Income Received]),FILTER('Income Receipts','Income Receipts'[Year]=EARLIER('Income Receipts'[Year])&&'Income Receipts'[Quarter]=EARLIER('Income Receipts'[Quarter])&&'Income Receipts'[Plan Number]=EARLIER('Income Receipts'[Plan Number]))),
"Monthly",CALCULATE(SUM('Income Receipts'[Income Received]),FILTER('Income Receipts','Income Receipts'[YEAR]=EARLIER('Income Receipts'[YEAR])&&'Income Receipts'[Month]=EARLIER('Income Receipts'[Month])&&'Income Receipts'[Plan Number]=EARLIER('Income Receipts'[Plan Number]))),
"Annually",CALCULATE(SUM('Income Receipts'[Income Received]),FILTER('Income Receipts','Income Receipts'[YEAR]=EARLIER('Income Receipts'[YEAR])&&'Income Receipts'[Plan Number]=EARLIER('Income Receipts'[Plan Number]))),
"Bi-Annual",CALCULATE(SUM('Income Receipts'[Income Received]),FILTER('Income Receipts','Income Receipts'[YEAR]>=EARLIER('Income Receipts'[YEAR])&&'Income Receipts'[YEAR]<=EARLIER('Income Receipts'[YEAR])+1&&'Income Receipts'[Plan Number]=EARLIER('Income Receipts'[Plan Number]))))

 

 

And create a relationship using this column:

vkellymsft_0-1624437517538.png

Finally in the filter pane,making the setting as below:

vkellymsft_0-1624440306084.png

 

 

And you will see:

vkellymsft_2-1624437586399.png

 

 For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

View solution in original post

9 REPLIES 9
amitchandak
Super User
Super User

@danakajoel , based on what I got. You can rolling like this example

 

Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-12,MONTH))

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

Thank you @amitchandak for taking the time to reply but I don't think that would give what I need?

Hi  @danakajoel ,

 

I created 2 sample tables as below:

vkellymsft_0-1623998361341.png

vkellymsft_1-1623998374237.png

Then create a measure as below:

Measure = 
var _lookupvalue=LOOKUPVALUE('Table 2'[Income Received],'Table 2'[Stock ID],MAX('Table'[Stock ID]),0)
Return
IF(MAX('Table'[Stock Value])>0&&_lookupvalue=BLANK(),1,0)

In the table visual,put measure in the filter pane ,select  measure is 1 .And you will see:

vkellymsft_3-1623998483516.png

 

vkellymsft_2-1623998417864.png

For the related .pbix file,pls see attached.

 

If above doesnt help solve your issue,remember to attach some sample data or .pbix file for test.

 

Best Regards,
Kelly

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

 

Hi Kelly. I'm really grateful for you looking to help.  I can see the approach you are taking.  The issue is that stocks receive money monthly, quarterly, bi annually etc and so it's identifying where receipts are missing against an expectation.  I attach some randomised data to give a flavour of the challenge which I hope helps. For Stocks above, read Plans

 

Struggling to figure out how to attach on here?!?!

Hi @danakajoel ,

 

You could upload your sample data to a Cloud service then share a public to us.

 

Best Regards,
Kelly

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

 

Thank you Kelly. Here's a randomised data set. Many thanks

 

https://1drv.ms/x/s!Ah__lQK3C3gfhvcQBqYAjlw0Foakvg?e=bSdPMi

 

Hi @danakajoel ,

First create 4 columns in both tables:

 

 

Frequency = LOOKUPVALUE('Plan Lookup'[Column2],'Plan Lookup'[Column1],'Income Receipts'[Plan Number],Blank())
YEAR = YEAR('Income Receipts'[Period End Date])
Month = MONTH('Income Receipts'[Period End Date])
Quarter = QUARTER('Income Receipts'[Period End Date])

 

 

Then create a total column in both tables:

 

 

_Total = SWITCH('Income Receipts'[Frequency],
"Ad-Hoc",CALCULATE(SUM('Income Receipts'[Income Received])),
"Quarterly",CALCULATE(SUM('Income Receipts'[Income Received]),FILTER('Income Receipts','Income Receipts'[Year]=EARLIER('Income Receipts'[Year])&&'Income Receipts'[Quarter]=EARLIER('Income Receipts'[Quarter])&&'Income Receipts'[Plan Number]=EARLIER('Income Receipts'[Plan Number]))),
"Monthly",CALCULATE(SUM('Income Receipts'[Income Received]),FILTER('Income Receipts','Income Receipts'[YEAR]=EARLIER('Income Receipts'[YEAR])&&'Income Receipts'[Month]=EARLIER('Income Receipts'[Month])&&'Income Receipts'[Plan Number]=EARLIER('Income Receipts'[Plan Number]))),
"Annually",CALCULATE(SUM('Income Receipts'[Income Received]),FILTER('Income Receipts','Income Receipts'[YEAR]=EARLIER('Income Receipts'[YEAR])&&'Income Receipts'[Plan Number]=EARLIER('Income Receipts'[Plan Number]))),
"Bi-Annual",CALCULATE(SUM('Income Receipts'[Income Received]),FILTER('Income Receipts','Income Receipts'[YEAR]>=EARLIER('Income Receipts'[YEAR])&&'Income Receipts'[YEAR]<=EARLIER('Income Receipts'[YEAR])+1&&'Income Receipts'[Plan Number]=EARLIER('Income Receipts'[Plan Number]))))

 

 

And create a relationship using this column:

vkellymsft_0-1624437517538.png

Finally in the filter pane,making the setting as below:

vkellymsft_0-1624440306084.png

 

 

And you will see:

vkellymsft_2-1624437586399.png

 

 For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

Hi Kelly, sorry, I've been working off site for the last couple of weeks. I'll look to update my model next week and let you know how I get on 😀

Hi  @danakajoel ,

 

It's OK,waiting for your feedback.

 

Best Regards,
Kelly

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

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.