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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
junaid2107
New Member

DAX to find Average daily volume based on 2 tables

Hello Power BI Community

 

I have the below scenario with 2 tables, The relationship between them is based on State and Date

Table 1:

DateLocationState Volume
1st Jan 2022AAAX10
1st Jan 2022BBBX20
1st Jan 2022CCCY25
2nd Jan 2022AAAX15
2nd Jan 2022BBBX15
2nd Jan 2022CCCY0

 

Table 2:

DateStateWorking Day
1st Jan 2022X1
1st Jan 2022Y1
2nd Jan 2022X1
2nd Jan 2022Y0

 

What i want to achieve is Average Daily volume for my date range (which will be a slicer). Explained below

Slicer Selection for Date - 1st to 2nd Jan 2022 (eg.). How could I go about doing this? is it possible through DAX, other solutions that are more efficient is also appreciated

 

LocationAverage Daily Volume
AAA(10+15)/(1+1) = 12.5
BBB(20+15)/(1+1) = 17.5
CCC(25+0)/(1+0) = 25

 

Regards,

Junaid

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @junaid2107 ,

I created a sample pbix file(see the attachment), please check if that is what you want.

1. Create a calendar table and create relationships with Table 1 and Table 2

yingyinr_1-1671502710635.png

2. Create a measure as below to get it:

Average Daily Volume = 
VAR _location =
    SELECTEDVALUE ( 'Table 1'[Location] )
VAR _volumn =
    SUM ( 'Table 1'[Volume] )
VAR _states =
    CALCULATETABLE (
        VALUES ( 'Table 1'[State] ),
        FILTER ( 'Table 1', 'Table 1'[Location] = _location )
    )
VAR _workingday =
    CALCULATE (
        SUM ( 'Table 2'[Working Day] ),
        FILTER ( 'Table 2', 'Table 2'[State] IN _states )
    )
RETURN
    DIVIDE ( _volumn, _workingday )

yingyinr_0-1671502618631.png

Best Regards

View solution in original post

9 REPLIES 9
junaid2107
New Member

I am trying to make the relation on a Concatenated field ie. Date+State (1stJan2022X,1st Jan2022Y...). But after joining, im not able to get the Average Volume as i need.

The concatenated field would make it a one to many relationship.

Hi @junaid2107 
Please try

Average Daily Volume =
SUMX (
    VALUES ( 'Table 1'[Location] ),
    CALCULATE (
        DIVIDE ( SUM ( 'Table 1'[Volume] ), SUM ( 'Table 2'[Working Day] ) ),
        CROSSFILTER ( 'Table 1'[Date+State], 'Table 2'[Date+State], BOTH )
    )
)

Hello tamerj1

 

Im trying out the below, let me know if it makes sense?

  • First i create a measure to get Working Days 

Working Days = CALCULATE(SUM('Table 2'[WORKING_DAY]),FILTER('Table 2','Table 2'[State] = VALUES('Table 1'[State])))

 

  • Then i use the above Working Days Measure to get Average Daily Volume
    Average Daily Volume = Sum(Volume)/WorkingDays

Hi @junaid2107 
Please try

Average Daily Volume =
SUMX (
    'Table 1',
    DIVIDE (
        'Table 1'[Volume],
        CALCULATE (
            SUM ( 'Table 2'[Working Day] ),
            CROSSFILTER ( 'Table 1'[Date+State], 'Table 2'[Date+State], BOTH )
        )
    )
)

Its only working for 1 day selected in my date slicer.

Working Days = CALCULATE(SUM('Table 2'[WORKING_DAY]),FILTER('Table 2','Table 2'[State] = VALUES('Table 1'[State])))

+

Average Daily Volume = Sum(Volume)/WorkingDays

seems to be more robust

Anonymous
Not applicable

Hi @junaid2107 ,

I created a sample pbix file(see the attachment), please check if that is what you want.

1. Create a calendar table and create relationships with Table 1 and Table 2

yingyinr_1-1671502710635.png

2. Create a measure as below to get it:

Average Daily Volume = 
VAR _location =
    SELECTEDVALUE ( 'Table 1'[Location] )
VAR _volumn =
    SUM ( 'Table 1'[Volume] )
VAR _states =
    CALCULATETABLE (
        VALUES ( 'Table 1'[State] ),
        FILTER ( 'Table 1', 'Table 1'[Location] = _location )
    )
VAR _workingday =
    CALCULATE (
        SUM ( 'Table 2'[Working Day] ),
        FILTER ( 'Table 2', 'Table 2'[State] IN _states )
    )
RETURN
    DIVIDE ( _volumn, _workingday )

yingyinr_0-1671502618631.png

Best Regards

Hello tamerj1

 

Interesting, It works for 1 category

'Table 1'[Location] 

, but i need to use this measure in another table visual as well and a couple more granular tables

the 2nd table visual has 2 categories

Location, Location Subtype

 

 

tamerj1
Super User
Super User

Hi @junaid2107 
My understanding that you have two many to many relationships between the 2 tables. In this case one of them only can be active. Would you please provide more details? Thank you

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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