Forum Discussion

ryan_b_fiting's avatar
ryan_b_fiting
Post Patron
3 years ago
Solved

Calculated Column removing filter context

Hello - 

 

I am trying to create a calculated column that will provide me the SUM of the cost based on a specific date value for the row in my table.

 

I have 4 main tables:

Wireless_Numbers, Date_Table, Overview of Lines, Monthly_Costs with the below sample data:

 

Wireless Numbers:

idWirelessnumber
1xxxxxxx
2xxxxxxx
3xxxxxxx
4xxxxxxx
5xxxxxxx
6xxxxxxx
7xxxxxxx

 

Overview of Lines (Cost is the column i want to calculate):

numberidwirelessnumberBill Cycle DateActivation DateBenchmark Cycle DateCost
1xxxxxxx1/1/20221/1/20191/1/2022                                   32.00
2xxxxxxx1/1/20221/2/20191/1/2022                                   31.00
3xxxxxxx1/1/20221/3/20191/1/2022                                   33.00
4xxxxxxx1/1/20221/4/20191/1/2022                                   33.00
5xxxxxxx1/1/20221/5/20191/1/2022                                   23.00
6xxxxxxx1/1/20221/6/20191/1/2022                                   26.00
1xxxxxxx2/1/20221/1/20191/1/2022                                   32.00
2xxxxxxx2/1/20221/2/20191/1/2022                                   31.00
3xxxxxxx2/1/20221/3/20191/1/2022                                   33.00
4xxxxxxx2/1/20221/4/20191/1/2022                                   33.00
5xxxxxxx2/1/20221/5/20191/1/2022                                   23.00
6xxxxxxx2/1/20221/6/20191/1/2022                                   26.00
7xxxxxxx2/1/20222/12/20222/1/2022                                   32.00
1xxxxxxx3/1/20221/1/20191/1/2022                                   32.00
2xxxxxxx3/1/20221/2/20191/1/2022                                   31.00
3xxxxxxx3/1/20221/3/20191/1/2022                                   33.00
4xxxxxxx3/1/20221/4/20191/1/2022                                   33.00
5xxxxxxx3/1/20221/5/20191/1/2022                                   23.00
6xxxxxxx3/1/20221/6/20191/1/2022                                   26.00
7xxxxxxx3/1/20222/12/20222/1/2022                                   32.00

 

Monthly_Cost

numberidwirelessnumberBill Cycle DateCost CategoryCost
1xxxxxxx1/1/2022Data Usage17
2xxxxxxx1/1/2022Data Usage17
3xxxxxxx1/1/2022Data Usage16
4xxxxxxx1/1/2022Data Usage16
5xxxxxxx1/1/2022Data Usage13
6xxxxxxx1/1/2022Data Usage14
1xxxxxxx2/1/2022Data Usage12
2xxxxxxx2/1/2022Data Usage15
3xxxxxxx2/1/2022Data Usage16
4xxxxxxx2/1/2022Data Usage18
5xxxxxxx2/1/2022Data Usage16
6xxxxxxx2/1/2022Data Usage18
7xxxxxxx2/1/2022Data Usage20
1xxxxxxx3/1/2022Data Usage17
2xxxxxxx3/1/2022Data Usage15
3xxxxxxx3/1/2022Data Usage18
4xxxxxxx3/1/2022Data Usage12
5xxxxxxx3/1/2022Data Usage14
6xxxxxxx3/1/2022Data Usage14
7xxxxxxx3/1/2022Data Usage11
1xxxxxxx1/1/2022Fees and Taxes15
2xxxxxxx1/1/2022Fees and Taxes14
3xxxxxxx1/1/2022Fees and Taxes17
4xxxxxxx1/1/2022Fees and Taxes17
5xxxxxxx1/1/2022Fees and Taxes10
6xxxxxxx1/1/2022Fees and Taxes12
1xxxxxxx2/1/2022Fees and Taxes11
2xxxxxxx2/1/2022Fees and Taxes10
3xxxxxxx2/1/2022Fees and Taxes10
4xxxxxxx2/1/2022Fees and Taxes12
5xxxxxxx2/1/2022Fees and Taxes13
6xxxxxxx2/1/2022Fees and Taxes15
7xxxxxxx2/1/2022Fees and Taxes12
1xxxxxxx3/1/2022Fees and Taxes20
2xxxxxxx3/1/2022Fees and Taxes13
3xxxxxxx3/1/2022Fees and Taxes20
4xxxxxxx3/1/2022Fees and Taxes15
5xxxxxxx3/1/2022Fees and Taxes20
6xxxxxxx3/1/2022Fees and Taxes15
7xxxxxxx3/1/2022Fees and Taxes15

 

Date Table is standard date dimensional table that is joined to the fact tables on Bill Cycle Date.

 

What I am looking to do is calculate the COST from the Monthly_cost table for the Benchmark Date associated with each Wireless number.  So even if we are looking at March 2022 reporting, I want to see what our cost was for January 2022 for the wirelessid 1, 2 etc.  

 

We need to compare our benchmark costs, versus our go forward monthly costs to see the monthly savings we are generating for each wireless number.

 

Is there a way to essentially create this SUMIF excel statement in Power BI:

SUMIFS(Cost, wireless number (Monthly Cost) = Wireless Number (row in Overview of Lines) AND Bill Cycle Date (Monthly Cost) = Benchmark Date (Overview of lines).

 

I have been trying to figure out this solution with no luck so any help would be great!

Thanks
Ryan

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi ryan_b_fiting ,

    Please refer to my pbix file to see if it helps you.

    Create relationships between tables.

    Create a column.

    Column =
    CALCULATE (
        SUM ( 'monthly cost'[Cost] ),
        FILTER (
            'monthly cost',
            'monthly cost'[wirelessnumber] = EARLIER ( 'Overview of Lines'[wirelessnumber] )
                && 'monthly cost'[Bill Cycle Date]
                    = EARLIER ( 'Overview of Lines'[Benchmark Cycle Date] )
        )
    )
    

    Or a measure.

    Measure_RE =
    CALCULATE (
        SUM ( 'monthly cost'[Cost] ),
        FILTER (
            ALL ( 'monthly cost' ),
            'monthly cost'[wirelessnumber]
                = SELECTEDVALUE ( 'Overview of Lines'[wirelessnumber] )
                && 'monthly cost'[Bill Cycle Date]
                    = SELECTEDVALUE ( 'Overview of Lines'[Benchmark Cycle Date] )
        )
    )
    

    How to Get Your Question Answered Quickly 

     

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

     

    Best Regards
    Community Support Team _ Polly

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

     

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi ryan_b_fiting ,

    Please refer to my pbix file to see if it helps you.

    Create relationships between tables.

    Create a column.

    Column =
    CALCULATE (
        SUM ( 'monthly cost'[Cost] ),
        FILTER (
            'monthly cost',
            'monthly cost'[wirelessnumber] = EARLIER ( 'Overview of Lines'[wirelessnumber] )
                && 'monthly cost'[Bill Cycle Date]
                    = EARLIER ( 'Overview of Lines'[Benchmark Cycle Date] )
        )
    )
    

    Or a measure.

    Measure_RE =
    CALCULATE (
        SUM ( 'monthly cost'[Cost] ),
        FILTER (
            ALL ( 'monthly cost' ),
            'monthly cost'[wirelessnumber]
                = SELECTEDVALUE ( 'Overview of Lines'[wirelessnumber] )
                && 'monthly cost'[Bill Cycle Date]
                    = SELECTEDVALUE ( 'Overview of Lines'[Benchmark Cycle Date] )
        )
    )
    

    How to Get Your Question Answered Quickly 

     

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

     

    Best Regards
    Community Support Team _ Polly

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

     

    • ryan_b_fiting's avatar
      ryan_b_fiting
      Post Patron

      Thanks Anonymous the column worked as expected.  The measure did not give me the expected output, but I am using the calculated column and it is working for me!

       

      Thanks again for the assistance.