Forum Discussion

SuperCal99's avatar
SuperCal99
Helper I
2 years ago
Solved

DAX - Location query

Hi,

 

I have the following sample data set:

customerIDCountyRegion
10001Greater LondonLondon
10002KentSouth East
10003SurreySouth East
10004BuckinghamshireSouth East
10005West SussexSouth East
10006OxfordshireSouth East
10007HampshireSouth East
10008Isle of WightSouth East
10009East SussexSouth East
10010BerkshireSouth East
10011HertfordshireEast of England
10012NorfolkEast of England
10013SuffolkEast of England
10014BedfordshireEast of England


I essentially want to create a table like the below, based on customer location:

County% across all counties%  within region
Greater London20%92%
Kent16%36%
Surrey14%56%


Across all counties is fine, but the % within region I have stuggling with. I get the correct values if i use region as a filter, for example, within the London region is 2 counties, Greater London and City London, which returns 99.8% and 0.2% respectively. I just want to achieve these figure without the use of a filter.

 

Thanks in advance for any guidance and help

 

Cal

  • Hi SuperCal99 based on your sample data, create 3 measures as following, adjust your Table name for sheet1

    Did I answer correctly? Kudos appreciate / accept solution.

     

    #Dist cust = DISTINCTCOUNT(Sheet1[customerID])
    % across all counties =
    DIVIDE([#Dist cust],CALCULATE([#Dist cust],ALL()))
    %  within region =
    DIVIDE([#Dist cust],
        CALCULATE([#Dist cust],
        REMOVEFILTERS(Sheet1),
        VALUES(Sheet1[Region])
        )
    )
     

     

3 Replies

  • some_bih's avatar
    some_bih
    Community Champion

    Hi SuperCal99 based on your sample data, create 3 measures as following, adjust your Table name for sheet1

    Did I answer correctly? Kudos appreciate / accept solution.

     

    #Dist cust = DISTINCTCOUNT(Sheet1[customerID])
    % across all counties =
    DIVIDE([#Dist cust],CALCULATE([#Dist cust],ALL()))
    %  within region =
    DIVIDE([#Dist cust],
        CALCULATE([#Dist cust],
        REMOVEFILTERS(Sheet1),
        VALUES(Sheet1[Region])
        )
    )
     

     

    • SuperCal99's avatar
      SuperCal99
      Helper I

      Hi some_bih , many thanks for your response
      I have created the measures you provided, the "%within region" measure generates the following error when adding it to the visual:

      MdxScript(Model) (62.9) Calculation error in measure 'ballot' [withinregion]: The alternative result to return on divide by zero cases must be a constant numeric value

      • some_bih's avatar
        some_bih
        Community Champion

        Hi SuperCal99 measure reference should be only with [xxx] not table before it, put [withinregion].

        Still, measure definition is based on another measure [#Dist cust], so process is important here, first create this measure [#Dist cust], and after that [withinregion].