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
Phil2ps
New Member

Calculate daily rate based on fields from different fact tables

Hi all,

 

I have 2 fact tables storing Open and Sent information. Using these tables I can display how many messages were sent/opened on a specific date.

There is also a separate dimension table storing date information. The date dimension is joined to the 2 fact tables on date fields. I use the date field from the dimension table as a slicer to filter and/or display the data over time.

 

fact_Sent

DateCountSentMessage_id
01/01/2023100A
01/01/2023200B

 

fact_Open

DateCountOpenMessage_id
01/01/202350A
02/01/202320A
01/01/202340B

 

I can built a simple visual showing:

 

Message_idDateCountSentCountOpen
A01/01/202310050
A02/01/2023NULL20
B01/01/202320040

 

As per above table, a message is sent on a specific day but the open can occur over multiple days.

 

Now I wanted to calculate the open rate ( CountOpen/CountSent) but I'm getting INFINITY values for days where CountSent is NULL.

I understand I should be able to create a measure to calculate the open rate but I'm struggling to build its logic. Essentially, the logic should be 'on date X, divide 'CountOpen from date X) by CountSent'.

 

The results I'm trying to get is:

 

Message_idDateCountSentCountOpenOpenRate
A01/01/20231005050%
A02/01/2023NULL2020%
B01/01/20232004020%

 

Any suggestion?

Thanks. 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Phil2ps 

You can refer to the following soltion.

1.Create a type table of message_id 

vxinruzhumsft_0-1697079296733.png

 

2.Create the relationship between the tables

vxinruzhumsft_1-1697079379850.png

 

3.Create the following measures

Sum_open = SUM(fact_Open[CountOpen]) 
Sum_sent = SUM(fact_Sent[CountSent])
Divide_ =
VAR _predate =
    IF (
        OR ( [Sum_open] <> BLANK (), [Sum_sent] <> BLANK () ),
        MAXX (
            FILTER (
                ALLSELECTED ( fact_Sent ),
                [Message_id]
                    IN VALUES ( 'Type'[Message_id] )
                        && [Date] < SELECTEDVALUE ( 'Date'[Date] )
                        && [CountSent] <> BLANK ()
            ),
            [Date]
        )
    )
VAR b =
    MAXX (
        FILTER (
            ALLSELECTED ( fact_Sent ),
            [Message_id]
                IN VALUES ( 'Type'[Message_id] )
                    && [Date] = _predate
        ),
        [CountSent]
    )
RETURN
    IF (
        [Sum_sent] <> BLANK (),
        DIVIDE ( [Sum_open], [Sum_sent] ),
        DIVIDE ( [Sum_open], b )
    )

Output

vxinruzhumsft_2-1697079510135.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Phil2ps 

You can refer to the following soltion.

1.Create a type table of message_id 

vxinruzhumsft_0-1697079296733.png

 

2.Create the relationship between the tables

vxinruzhumsft_1-1697079379850.png

 

3.Create the following measures

Sum_open = SUM(fact_Open[CountOpen]) 
Sum_sent = SUM(fact_Sent[CountSent])
Divide_ =
VAR _predate =
    IF (
        OR ( [Sum_open] <> BLANK (), [Sum_sent] <> BLANK () ),
        MAXX (
            FILTER (
                ALLSELECTED ( fact_Sent ),
                [Message_id]
                    IN VALUES ( 'Type'[Message_id] )
                        && [Date] < SELECTEDVALUE ( 'Date'[Date] )
                        && [CountSent] <> BLANK ()
            ),
            [Date]
        )
    )
VAR b =
    MAXX (
        FILTER (
            ALLSELECTED ( fact_Sent ),
            [Message_id]
                IN VALUES ( 'Type'[Message_id] )
                    && [Date] = _predate
        ),
        [CountSent]
    )
RETURN
    IF (
        [Sum_sent] <> BLANK (),
        DIVIDE ( [Sum_open], [Sum_sent] ),
        DIVIDE ( [Sum_open], b )
    )

Output

vxinruzhumsft_2-1697079510135.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

mickey64
Super User
Super User

For your reference.

 

Step 1: I add a relationship.

mickey64_0-1697016774211.png

 

Step 2: I make a measure.

    Open % = DIVIDE(SUM('fact_Open'[CountOpen]),SUM('fact_Sent'[CountSent]))

 

Step 3: I make a 'Table' visual.

    mickey64_1-1697016900921.png

 

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.