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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Dunner2020
Post Prodigy
Post Prodigy

Creating sum column in dimension table

Hi there,

I have a data model which looks as follow:

leo_89_0-1618054960505.png

 

The daily activity table contains fine-grained data. Now I want to create two columns in the Master table which contains sum of EventDuration and NumberofConsumers columns of the Daily Activity table when both tables have the same EpochHH.

Same EpochHH Sum EventDuration =

CALCULATE(SUM('Daily Activity'[EventDuration]),FILTER('Daily Activity','Daily Activity'[EpochHH] = MAX('Master Table'[EpochHH]))

However, it did not produce the result. In fact it return blank row. Could you guide me where am I making the mistake?

Here is sample file from here

1 ACCEPTED SOLUTION

The problem you are having in your original view is the EpochHH in the master table is only in 30 min increments where the EpochHH on the 'Daily Activity' is in 1 minute increments.  If you fix your Master table to be in 1 min increments then this will sum all the amounts from the 'Daily Activity' onto the Master.

Event Duration = CALCULATE(SUM('Daily Activity'[EventDuration]))

jdbuchanan71_0-1618147537551.png

 

View solution in original post

5 REPLIES 5
jdbuchanan71
Super User
Super User

@Dunner2020 

I think you want to go more like this for your model.  

jdbuchanan71_0-1618063618839.png

Building a master table with every date/time combination (Master table) is definitely not a good way to do it.

You need to make sure your time fields are Date type: Time instead of Date/time

jdbuchanan71_1-1618063686315.png

Then you would use measures against your daily activity with fields from your date and time tables:

Event Duration = SUM ('Daily Activity'[EventDuration] )
Consumers = SUM ( 'Daily Activity'[NumberOfConsumers] )

To get views of your data

jdbuchanan71_2-1618063981682.png

I have attached my updated version of your sample for you to look at.

@jdbuchanan71 thanks for the reply. However, I want to sum both columns in term of EpochHH and want to save in seperate table (such as Master Table).

The create your master table like this.

Master Table = 
    ADDCOLUMNS (
        SUMMARIZE ( 'Daily Activity','Daily Activity'[EpochHH] ),
        "Duration", CALCULATE ( SUM ('Daily Activity'[EventDuration] ) ),
        "Consumers", CALCULATE ( SUM ( 'Daily Activity'[NumberOfConsumers] ) )
    )

jdbuchanan71_0-1618093963780.png

 

@jdbuchanan71 , the only issue with your proposed solution is that it only treats those EpcohHH that are present in the Daily activity table. However, I want to create a master table, which has EpochHH values that represent date from 1/1/2020 to 31/12/2025. So the EpochHH that represent dates that are not in daily activity should also be shown in the master table (although the values would be zeros for duration and consumers columns). Is there anyway that we can do that?   

The problem you are having in your original view is the EpochHH in the master table is only in 30 min increments where the EpochHH on the 'Daily Activity' is in 1 minute increments.  If you fix your Master table to be in 1 min increments then this will sum all the amounts from the 'Daily Activity' onto the Master.

Event Duration = CALCULATE(SUM('Daily Activity'[EventDuration]))

jdbuchanan71_0-1618147537551.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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