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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
michaelccdf
Helper I
Helper I

RelatedTable

I have three tables

 

factClosures

Date,School,PeriodsClosed

 

dimSchools

School, CountofHomerooms

 

dimDates

Date, Week

 

I'm trying to find the PeriodsClosed Per Homeroom Per Week.  The trouble is, the CountofHomerooms field in dimSchools does not seem to "link" to factClosures in PowerBI.  

 

In SQL I would do something like the below to calculate this (there is probably a better way to do this, I'm not at all a SQL expert)

 

SELECT

Week,

SUM(PeriodsClosed) / SUM(CountofHomerooms) as PeriodsClosedPerHomeroom

FROM

(SELECT

dimDates.Week,

dimSchools.School,

dimSchools.CountofHomeRooms,

SUM(factClosures.PeriodsClosed) as PeriodsClosed

FROM factClosures

JOIN dimSchools ON factClosures.School = dimSchools.School

JOIN dimDates ON factClosures.Date = dimDates.Date

GROUP BY 

dimDates.Week,

dimSchools.School,

dimSchools.CountofHomeRooms) as query1

GROUP BY week

 

Any ideas how I might do this in PowerBI directly ?

 

1 ACCEPTED SOLUTION

I read your first post again and understud.

Try this way:

1. Edit relationship between factClosures and dimSchools and set Filter Direction = "To both tables" 

2. Replace Measure formula:
PeriodsClosed Per Homeroom =
CALCULATE (
    DIVIDE (
        SUM ( factClosures[PeriodsClosed] );
        SUM ( dimSchools[CountofHomerooms] )
    )
)

View solution in original post

4 REPLIES 4
popov
Resolver III
Resolver III

Hello. 
Follow steps below:

1. Add tables to Power BI Desktop

2. Create relationship between factClosures and dimDates, and between factClosures and dimSchools

3. Create claculated column in table factClosures using formula:

CountofHomerooms=RELATED(dimSchools[CountofHomerooms])

4. Create Measure 
PeriodsClosed Per Homeroom =
CALCULATE (
    DIVIDE (
        SUM ( factClosures[PeriodsClosed] );
        SUM ( factClosures[CountofHomerooms] )
    )
)

thank you popov, this is almost what I am looking for.  The difficulty is that I only need the total homerooms for schools that reported in a given week.  Something like

 

sum(all the periods closed in a given week) / sum(homerooms of distinct schools that reported in a given week)

 

in other words, I need to group by week and school

 

does that make sense?  Thanks a lot for the help. 

I read your first post again and understud.

Try this way:

1. Edit relationship between factClosures and dimSchools and set Filter Direction = "To both tables" 

2. Replace Measure formula:
PeriodsClosed Per Homeroom =
CALCULATE (
    DIVIDE (
        SUM ( factClosures[PeriodsClosed] );
        SUM ( dimSchools[CountofHomerooms] )
    )
)

wow, this works great!  Setting cross filter direction to both unlocks the magic!  Thanks so much.

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.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

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.

Top Solution Authors