Forum Discussion

kkjj's avatar
kkjj
Frequent Visitor
4 years ago

Not hard code with filter formula in Dax

Hi All

 

I would like to not hard code this filter function. I basically want it to filter over Hotel Details[Hotel] and match with Activity 2013 [Business unit] so I do not have to go through and hard code it for each different location. I think I have the right concept but there is something that I am not getting. If I hard code it then it works. But if I try to replace the hard code and add the second filter it breaks.  Is there a different function or conecpt  I need to use?

 

Emissions/m2 = SUMX(
                     FILTER(
                         'Hotel Details',
                                //FILTER('Activity 2013',
                                    'Hotel Details'[Hotel]="Airport"//'Activity 2013'[Business unit]
                                    ),
                                                       
                             'Activity 2013'[EmissionsBU]/ 'Hotel Details'[Area]
                                )
 

Thanks a lot 

3 Replies

  • kkjj , Not very clear, But if you use a slicer on hotel of hotel details, it should work based on selection, no need for filter code 

    • kkjj's avatar
      kkjj
      Frequent Visitor

      Hi

       

      Thanks for your reply. 

      How do I use the slicer? 

       

      I have the following tables

      Activity 2013

       

      Hotel Details

       

      I want to be able to make a graph where I can see what each hotel's emissions are per m2 ie 'Activity 2013' [EmissionsBU] / 'Hotel Details' [Area]. 

       

      How do I use the slicer to be able to see all the hotels in one graph? My code above is working because I hardcoded the location "Airport".  But I want to get all the locations not jsut airport. When I try to make it loop through the locations so they "match" then the code stops working. 

      Ie when it looks like this:

      Emissions/m2 = SUMX(
                           FILTER(
                               'Hotel Details',
                                      FILTER('Activity 2013',
                                          'Hotel Details'[Hotel]='Activity 2013'[Business unit]
                                          ),
                                                             
                                   'Activity 2013'[EmissionsBU]'Hotel Details'[Area]
                                      )

      Hope that makese sense. 

      Thanks 

  • v-xiaotang's avatar
    v-xiaotang
    Community Support

    Hi kkjj 

    Thanks for reaching out to us.

    >> But if I try to replace the hard code and add the second filter it breaks.  Is there a different function or conecpt  I need to use?

    please try this measure

    Emissions/m2 = SUMX(
                         FILTER(
                             'Hotel Details',
                                    //FILTER('Activity 2013',
                                        'Hotel Details'[Hotel]="Airport" && Activity 2013'[Business unit] = min(Activity 2013'[Business unit])//'Activity 2013'[Business unit]
                                        ),
                                                           
                                 'Activity 2013'[EmissionsBU]'Hotel Details'[Area]
                                    )

     

    Best Regards,

    Community Support Team _Tang

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