- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Help with Intersect Function
HI, I just new to Power BI and having difficult time in using Intersect function. Basically I have a single Sales table with multi year data. I created an unrelated Dates table from the Sales table to use for Slicers. I was able to create a measure for line chart but the chart is not displaying full year for last year.
The expression I have is below. I am trying to find the Source ID that is in both years for the corresponding month and calculate the sum of Sales.
What I am seeing is below
What I want to see is somthing like below. Full year data for last year and only the data thats available fo rcurrent year. I know its not data related issue as I already checked it. Is Intersect correct method to use in this case? I also tried to create multi line chart with two measures for last year and current year without any luck.
Your help is appriciated
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @raj111983 ,
I updated your sample pbix file(see the attachment), please check if that is what you want.
Chart PTran =
VAR _selyear =
SELECTEDVALUE ( 'Dates'[Date].[Year] )
VAR _prevyear =
SELECTEDVALUE ( 'Dates'[Date].[Year] ) - 1
VAR _month =
SELECTEDVALUE ( 'Sales'[Date].[Month] )
VAR _CSource =
CALCULATETABLE (
VALUES ( 'Sales'[Source ID] ),
FILTER ( ALLSELECTED ( 'Sales' ), 'Sales'[Date].[Year] = _selyear )
)
VAR _PSource =
CALCULATETABLE (
VALUES ( 'Sales'[Source ID] ),
FILTER ( ALLSELECTED ( 'Sales' ), 'Sales'[Date].[Year] = _prevyear )
)
VAR _tab =
INTERSECT ( _CSource, _PSource )
RETURN
CALCULATE (
SUM ( Sales[Measure Value] ),
FILTER (
'Sales',
'Sales'[Date].[Year] = _prevyear
&& 'Sales'[Date].[Month] = _month
&& 'Sales'[Measure Name] = "Volume"
&& 'Sales'[Source ID] IN _tab
)
)
Best Regards
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @raj111983 ,
I created a sample pbix file(see the attachment), please check if that is what you want.
Sel year values =
VAR _selyear =
SELECTEDVALUE ( 'Dates'[Year] )
RETURN
CALCULATE (
SUM ( 'Sales'[Measure Value] ),
FILTER (
ALLSELECTED ( 'Sales' ),
'Sales'[Measure Name] = "Volume"
&& 'Sales'[Year] = _selyear
&& FORMAT ( 'Sales'[Date], "mmmm" ) = SELECTEDVALUE ( 'Sales'[Date].[Month] )
)
)
Pre year values =
VAR _selyear =
SELECTEDVALUE ( 'Dates'[Year] )
RETURN
CALCULATE (
SUM ( 'Sales'[Measure Value] ),
FILTER (
ALLSELECTED ( 'Sales' ),
'Sales'[Measure Name] = "Volume"
&& 'Sales'[Year] = _selyear - 1
&& FORMAT ( 'Sales'[Date], "mmmm" ) = SELECTEDVALUE ( 'Sales'[Date].[Month] )
)
)
Best Regards
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
THank you very much for the reply. But that is not what I was looking for. I posted a sample file and more explanation of what I was looking for. I am trying calculate current year and previous for onlt the Source ID's that are reporting data for corrsponding months in each year. Lets say, if Source ID "A" is only reporting data for January and March for one of the years then that Source ID should only be included for Jan and March for both current and previous years.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please supply your data, it makes it so much easier to debug than just some images.
Thanks
Phil
Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.
Blog :: YouTube Channel :: Connect on Linkedin
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Sample data is in Drop Box folder. Please le tme know if you can access it.
As you can see the data, Source ID AHA is present in 2024 so that shouldnt be included in the chart for current or previous year. Same with Source ID FKA, data is not availabel for Jan2023 so it shouldnt be included in Jan2024 sum. This is to Apples-Apples comparisionby Source ID and Month. I want to show full year last year and current year. But when I use intersect function, its only showing the data till Septemper.
Thank you!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Here is the pbix with sample data. I wanted the previous year
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @raj111983 ,
I updated your sample pbix file(see the attachment), please check if that is what you want.
Chart PTran =
VAR _selyear =
SELECTEDVALUE ( 'Dates'[Date].[Year] )
VAR _prevyear =
SELECTEDVALUE ( 'Dates'[Date].[Year] ) - 1
VAR _month =
SELECTEDVALUE ( 'Sales'[Date].[Month] )
VAR _CSource =
CALCULATETABLE (
VALUES ( 'Sales'[Source ID] ),
FILTER ( ALLSELECTED ( 'Sales' ), 'Sales'[Date].[Year] = _selyear )
)
VAR _PSource =
CALCULATETABLE (
VALUES ( 'Sales'[Source ID] ),
FILTER ( ALLSELECTED ( 'Sales' ), 'Sales'[Date].[Year] = _prevyear )
)
VAR _tab =
INTERSECT ( _CSource, _PSource )
RETURN
CALCULATE (
SUM ( Sales[Measure Value] ),
FILTER (
'Sales',
'Sales'[Date].[Year] = _prevyear
&& 'Sales'[Date].[Month] = _month
&& 'Sales'[Measure Name] = "Volume"
&& 'Sales'[Source ID] IN _tab
)
)
Best Regards
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you!! Worked Perfectly!!

Helpful resources
Subject | Author | Posted | |
---|---|---|---|
02-06-2025 01:14 AM | |||
03-03-2021 12:53 PM | |||
03-26-2025 07:46 AM | |||
02-19-2025 10:42 PM | |||
Anonymous
| 01-27-2020 02:06 PM |