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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
EZimmet
Resolver I
Resolver I

Assistance with Filter not working as expected

TY for assisting with this one,

 

Not sure where my filter is failing but here goes:

  • I Filter on Column A, E
  • I have a multiple Clients this one is at 4 locations
  • 3 of the locations I need to do a Calculation for Emissions & MWh
  • 1 Location in the example below [ Site 4 ]No Calculation I just need to pull the Raw numbers for MT CO2e & MWh from the input file

 

Screenshot 2024-05-06 101600.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Input File:

ABCDEF
Cal / No CalcDateClientSiteCategoryValue
Calc8/1/2023ABCSite 1Emissions600
Calc8/1/2023ABCSite 1MWh1707
Calc8/1/2023ABCSite 2Emissions636
Calc8/1/2023ABCSite 2MWh2119
Calc8/1/2023ABCSite 3Emissions691
Calc8/1/2023ABCSite 3MWh1314
No Cal8/1/2023ABCSite 4MT CO2e113
No Cal8/1/2023ABCSite 4MWh214
Calc9/1/2023ABCSite 1Emissions522
Calc9/1/2023ABCSite 1MWh1629
Calc9/1/2023ABCSite 2Emissions522
Calc9/1/2023ABCSite 2MWh2033
Calc9/1/2023ABCSite 3Emissions565
Calc9/1/2023ABCSite 3MWh1294
No Cal9/1/2023ABCSite 4MT CO2e90
No Cal9/1/2023ABCSite 4MWh206

 

Current CODE:

 

_Numbers =

// Pulls from Live DB

// Good Index 4 --------------------------------------------------------------------------------------------------

    VAR _rack =

    COUNTROWS ( FILTER (( '__SQL Query' ),'__SQL Query'[EQType] = "Rack") )

// Good Index 5 --------------------------------------------------------------------------------------------------  

    VAR _mainframe =

    COUNTROWS ( FILTER (( '__SQL Query' ),'__SQL Query'[EQType] = "Mainframe") )

// Good Index 6 --------------------------------------------------------------------------------------------------  

    VAR _storage_frame =

    COUNTROWS ( FILTER (( '__SQL Query' ),'__SQL Query'[EQType] = "Storage Frame") )

// Good Index 7 --------------------------------------------------------------------------------------------------                        VAR _storage_frame_mainframe =

    COUNTROWS ( FILTER (( '__SQL Query' ),'__SQL Query'[EQType] = "Storage Frame - Mainframe") )

 

// Filter for each Value from Input File

 // Index 9 --------------------------------------------------------------------------------------------------------------------

VAR _Cal_MWh =

     CALCULATE(

        SUM('Client Report'[Value] ),

            FILTER (( 'Client Report' ), 'Client Report'[Cal / No Calc] = "Calc") ,    

            FILTER (( 'Client Report' ), 'Client Report'[Category] = "MWh") )

// Index 10 -------------------------------------------------------------------------------------------------------------------

VAR _Cal_Emissions =

     CALCULATE(

        SUM('Client Report'[Value] ),

            FILTER (( 'Client Report' ), 'Client Report'[Cal / No Calc] = "Calc") ,

            FILTER (( 'Client Report' ), 'Client Report'[Category] = "Emissions") )

// Index 11 ------------------------------------------------------------------------------------------------------------------

VAR _No_Cal_MWh =

     CALCULATE(

        SUM('Client Report'[Value] ),

           FILTER (( 'Client Report' ), 'Client Report'[Cal / No Calc] = "No Cal") ,  

           FILTER (( 'Client Report' ), 'Client Report'[Category] = "MWh") )

// Index 12 -------------------------------------------------------------------------------------------------------------------

VAR _No_Cal_MT_CO2e =

     CALCULATE(

        SUM('Client Report'[Value] ),

           FILTER (( 'Client Report' ), 'Client Report'[Cal / No Calc] = "No Cal") ,  

           FILTER (( 'Client Report' ), 'Client Report'[Category] = "MT CO2e") )

 

//------------------------------------------------------------------------------------------------------------------------------

RETURN

    SWITCH (

        TRUE (),

 

 //– Value from Index 11

    MAX ( '_Output'[Expected] ) = "Total Electricity usage for month MWh_nc", (_No_Cal_MWh ),

 

 //– Value from Index 12

    MAX ( '_Output'[Expected] ) = "Total Carbon Emission for month Co2e_nc", (_No_Cal_MT_CO2e ),

 

 //– Value from Index 9

    MAX ( '_Output'[Expected] ) = "Total Electricity usage for month MWh", ((( _rack + _mainframe + _storage_frame + _storage_frame_mainframe ) * (1.5 * 730 * 1.75 / 1000) + _Cal_MWh )),

 

 //– Value from Index 10 

    MAX ( '_Output'[Expected] ) = "Total Carbon Emission for month Co2e", ((( _rack + _mainframe + _storage_frame + _storage_frame_mainframe ) * (1.5 * 730 * 1.75 / 1000) + _Cal_Emissions ))

 

    )

 

1 ACCEPTED SOLUTION

I ended up adding more filters to the calculations to seperate the results them combined the results into the total section 

View solution in original post

3 REPLIES 3
v-nuoc-msft
Community Support
Community Support

Hi @EZimmet 

 

Here I suggest you try the following actions:

 

First, make sure that the correct table relationships are established.

 

Instead of using MAX to get a single value from a column, consider using the SELECTEDVALUE function.

 

I made the following modifications to your code:

_Numbers =
// Pulls from Live DB
// Good Index 4 --------------------------------------------------------------------------------------------------
    VAR _rack =
    COUNTROWS ( FILTER (( '__SQL Query' ),'__SQL Query'[EQType] = "Rack") )
// Good Index 5 --------------------------------------------------------------------------------------------------  
    VAR _mainframe =
    COUNTROWS ( FILTER (( '__SQL Query' ),'__SQL Query'[EQType] = "Mainframe") )
// Good Index 6 --------------------------------------------------------------------------------------------------  
    VAR _storage_frame =
    COUNTROWS ( FILTER (( '__SQL Query' ),'__SQL Query'[EQType] = "Storage Frame") )
// Good Index 7 --------------------------------------------------------------------------------------------------                        VAR _storage_frame_mainframe =
    COUNTROWS ( FILTER (( '__SQL Query' ),'__SQL Query'[EQType] = "Storage Frame - Mainframe") )
 
// Filter for each Value from Input File
 // Index 9 --------------------------------------------------------------------------------------------------------------------
VAR _Cal_MWh =
     CALCULATE(
        SUM('Client Report'[Value] ),
            'Client Report'[Cal / No Calc] = "Calc" ,    
            'Client Report'[Category] = "MWh") 

// Inde
VAR _Cal_Emissions =
     CALCULATE(
        SUM('Client Report'[Value] ),
            'Client Report'[Cal / No Calc] = "Calc" ,
            'Client Report'[Category] = "Emissions") 

// Index 11 ------------------------------------------------------------------------------------------------------------------
VAR _No_Cal_MWh =
     CALCULATE(
        SUM('Client Report'[Value] ),
          'Client Report'[Cal / No Calc] = "No Cal" ,  
          'Client Report'[Category] = "MWh") 

// Index 12 -------------------------------------------------------------------------------------------------------------------
VAR _No_Cal_MT_CO2e =
     CALCULATE(
        SUM('Client Report'[Value] ),
           'Client Report'[Cal / No Calc] = "No Cal" ,  
           'Client Report'[Category] = "MT CO2e") 

//------------------------------------------------------------------------------------------------------------------------------
RETURN
    SWITCH (
        TRUE (), 
 //– Value from Index 11
   SELECTEDVALUE( '_Output'[Expected] ) = "Total Electricity usage for month MWh_nc", _No_Cal_MWh , 

 //– Value from Index 12
    SELECTEDVALUE( '_Output'[Expected] ) = "Total Carbon Emission for month Co2e_nc", _No_Cal_MT_CO2e ,

 //– Value from Index 9

    SELECTEDVALUE( '_Output'[Expected] ) = "Total Electricity usage for month MWh", 
    ( _rack + _mainframe + _storage_frame + _storage_frame_mainframe ) * (1.5 * 730 * 1.75 / 1000) + _Cal_MWh , 

 //– Value from Index 10 

    SELECTEDVALUE( '_Output'[Expected] ) = "Total Carbon Emission for month Co2e", 
    ( _rack + _mainframe + _storage_frame + _storage_frame_mainframe ) * (1.5 * 730 * 1.75 / 1000) + _Cal_Emissions 
    )

 

Regards,

Nono Chen

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

Same Results the two lines with the Red X still showing

 

Screenshot 2024-05-07 111639.png

I ended up adding more filters to the calculations to seperate the results them combined the results into the total section 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.