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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Calculate percentage over time from two tables

Hi, I have two tables in power BI that look like

 

projects

ProjectCategory
AC1
BC2
CC1
DC2
EC2

 

project_years

ProjectYear
A2015
B2015
B2016
C2016
D2016
E2016

 

they are connected by the Project column

 

I want to calculate the % of projects in each category over time e.g.

YearCategoryPercentage
2015C150
2015C250
2016C125
2016C275

which in SQL would be

with projects as (
select 'A' as project, 'C1' as category
union
select 'B' as project, 'C2' as category
union
select 'C' as project, 'C1' as category
union
select 'D' as project, 'C2' as category
union
select 'E' as project, 'C2' as category
), project_years as (
select 'A' as project, 2015 as year
union
select 'B' as project, 2015 as year
union
select 'B' as project, 2016 as year
union
select 'C' as project, 2016 as year
union
select 'D' as project, 2016 as year
union
select 'E' as project, 2016 as year
)
select
year,
category,
100 * count(*)/sum(count(*)) over (partition by year)
from
projects p
inner join project_years y on y.project = p.project
group by category, year

I'm not sure how to do this in power BI because they're in separate tables - is there a way to do the join and counting in a measure or do they need to be joined in a query and then a measure done on that?

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi, @Anonymous 

Please check the below picture and the sample pbix file's link down below.

 

Picture3.png

 

Percentage =
DIVIDE (
CALCULATE (
COUNTROWS ( Projects ),
CROSSFILTER ( 'Project Years'[Project], Projects[Project], BOTH )
),
CALCULATE (
COUNTROWS ( Projects ),
ALLSELECTED ( Projects[Category] ),
CROSSFILTER ( 'Project Years'[Project], Projects[Project], BOTH )
)
)

 

 

https://www.dropbox.com/s/dpdu5n15pnrnp97/richard.pbix?dl=0 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi, @Anonymous 

Please check the below picture and the sample pbix file's link down below.

 

Picture3.png

 

Percentage =
DIVIDE (
CALCULATE (
COUNTROWS ( Projects ),
CROSSFILTER ( 'Project Years'[Project], Projects[Project], BOTH )
),
CALCULATE (
COUNTROWS ( Projects ),
ALLSELECTED ( Projects[Category] ),
CROSSFILTER ( 'Project Years'[Project], Projects[Project], BOTH )
)
)

 

 

https://www.dropbox.com/s/dpdu5n15pnrnp97/richard.pbix?dl=0 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Anonymous
Not applicable

Fantastic, thank you for the help

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.