Forum Discussion

jrodriguez's avatar
jrodriguez
Regular Visitor
10 years ago
Solved

Level of Detail Calcs

Hey Guys,

 

For those familiar with Tableau.....does Power BI have a way to do level of detail calculations?

 

http://www.tableau.com/LOD-expressions.

 

Any help would be appreciated.

 

Thanks,

 

Joe

  • Yes, in Power BI this is done through DAX filter expressions combined with measures, for example:

     

    = CALCULATE( SUM('ResellerSales_USD'[SalesAmount_USD]),ALL('ResellerSales_USD'))

     

    A measure defined this way would give you the SUM of [SalesAmount_USD] regardless of any visual-level filters/selections. There are a number of these types of filter functions, ALL, ALLEXCEPT, etc.

24 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    Yes, in Power BI this is done through DAX filter expressions combined with measures, for example:

     

    = CALCULATE( SUM('ResellerSales_USD'[SalesAmount_USD]),ALL('ResellerSales_USD'))

     

    A measure defined this way would give you the SUM of [SalesAmount_USD] regardless of any visual-level filters/selections. There are a number of these types of filter functions, ALL, ALLEXCEPT, etc.

    • Bmsams's avatar
      Bmsams
      New Member

      I am not sure if you ever used tableau but the formula I would use is { FIXED [ItemLoc],[Period]: SUM([ActualDemand UNITS ])}. How do I translate this into a Dax function? I tried =calculate(sum( vdemand[actual demand Units], Vdemand[ItemLocation], vdemand[period]) but recieve an error that itemlocation cannot be turned into a true or false statement.

      • Sean's avatar
        Sean
        Icon for Community Champion rankCommunity Champion

        Bmsams you have to specify the filter conditions - let me know if this helps

         

        = CALCULATE ( SUM(vdemand[actual demand Units]), vdemand[ItemLocation]="USA", vdemand[period]=2015)

         

         

  • Were you able to figure out how to do this?  I, too, am a Tableau user and I am very familiar with LOD calcs.  I have just started using Power BI but I am stuck on a project right now because I need to be able to perform a similar calc to an LOD.

    • belmore's avatar
      belmore
      Icon for Helper II rankHelper II

      I was not able to get an answer........it must be very painful to recreate (if at all) using DAX. Please let me know if you we able to learn anything.

       

      thank you

      • ldacey's avatar
        ldacey
        Icon for Advocate I rankAdvocate I

        Just want to add that I am working on some LOD-type calculations and I am having a lot of trouble reproducing accurate results, even when following the steps above.

         

  • Sripriya's avatar
    Sripriya
    Frequent Visitor

    This is not a suggested approach, but you can achieve the FIXED LOD concept in tableau using Group By function in Power BI query editor. Create a duplicate query with the fixed data that you want and later you can merge the data and use it for other visulaizations. This worked for me. Hope this works for you too. :)

     

     

     

    • alm5084's avatar
      alm5084
      Icon for Helper II rankHelper II

      Sripriya Your solution would technically work, but only with smaller amounts of data. If your grouped query result is several million rows, and your ungrouped query result is 10s of millions of rows, the query might hang forever trying to run. I've had this happen with complicated data heavy queries. The more appropriate solution for calculating a measure at a different level of granularity is to write a level of detail measure in DAX. It can be confusing at first, but once you understand the pattern you can reproduce it easily.

       

      If you need a grouped table result - the only reason you would is if you need to use the columns as a categorical axis in a visual - you can create the table using a DAX statement as well. This is the data modeling version of a database view, whereas duplicating the query with a grouped statement would be the database equivalent of actually duplicating the data in a second table. You don't ever want to actually duplicate the data. It not only increases the size and complexity of your Power BI file, it also introduces an additional place for user error when you are updating the data later.  

  • jburia's avatar
    jburia
    Regular Visitor

    Hello, I'm having a similar issue migrating from Tableau. My dataset has several levels within one flattened table. As you can see in the screenshot, the Miles for each Bill of Lading are duplicated across each of the Business Units.

     

    In Tableau, I can calculate an Average Miles per Load using the Average of the following LOD Function to calculate Average Miles per Load BOL Number. How can I use DAX to perform the same calculation?

     

    {Fixed [Load BOL Nbr DESC],[Ship Day]: Max([Load Hhm  Miles])}

     

    Load 4971121 -               171 Miles

    Load 4971125 -               354 Miles

    Average Miles per Load - (354+179)/Distinct BOL Count (2) = 266.5

    Tableau Screenshot:

     

    • alm5084's avatar
      alm5084
      Icon for Helper II rankHelper II

       

       

      Hi jburia,

       

      I'm not sure if you ever figured this out, but it is doable in Dax. It's funny because I came to this board looking for help to translate Dax into Tableau calculations. You could try this calculation (I added the data as a table named Table):

       

      Calculation =
      IF(DISTINCTCOUNT('Table'[Allocation])=1,
              CALCULATE(
                   MAXX('Table'[Load Hhm Miles]),
                  ALLEXCEPT('Table','Table'[Load BOL Nbr DESC])),
      AVERAGEX(
             SUMMARIZE('Table','Table'[Load BOL Nbr DESC],"MaxMiles",MAX('Table'[Load Hhm Miles])),[MaxMiles])
      )

       

      The big difference between Power BI and Tableau in this case is that you can't calculate the total differently from the rest of the measure in the visual. In Tableau, you can add your [Load Miles] calculation to the table, and then add a total and tell it to average that total. In Power BI, the total row calculates with exactly the same measure formula as the rest of the rows in the visual. So, to get a different calculation for the total row we use the IF statement to test whether there is more than one [Allocation] value, and return a different calculation based on the result of the logical test.

       

      If there is only one value for [Allocation] then it calculates the max [Load Hhm Miles] per [Load BOL Nbr DESC]. The CALCULATE function is the level of detail expression for Power BI, like your Fixed function in Tableau. The magic here is the filter for the CALCULATE, which is the ALLEXCEPT. This says to ignore all context except the [Load BOL Nbr DESC].

       

      If there is more than one value for [Allocation] as is the case for the Total row, then it uses the AVERAGEX calculation. AVERAGEX takes as its arguments a table and an expression to average over. So we create a summarized table to pass to AVERAGEX with SUMMARIZE, where we calculate the max[Load Hhm Miles] per [Load BOL Nbr DESC]. AVERAGEX then averages these max[Load Hhm Miles], and returns the proper result in the total row. These are my results:

       

      Load BOL Nbr DESCBusiness UnitAllocationLoad Hhm MilesCalculation
      4971121PLNAPLNA23179
      4971121PLNAPLNA179179
      4971125GCGC MISC84354
      4971125GCGC MISC354354
      4971125PLNAPLNA50354
      4971125PLNAPLNA61354
      4971125TCARTCAR46354
      4971125TCARTCAR76354
      Total   266.5

       

      This is the sample data I entered into Table:

       

      Load BOL Nbr DESCBusiness UnitShip DayLoad Hhm MilesAllocation
      4971121PLNA1/1/2016179PLNA
      4971125GC1/1/2016354GC MISC
      4971125PLNA1/2/201650PLNA
      4971125TCAR1/3/201646TCAR
      4971121PLNA1/1/201623PLNA
      4971125GC1/1/201684GC MISC
      4971125PLNA1/2/201661PLNA
      4971125TCAR1/3/201676TCAR
      • StevenHB's avatar
        StevenHB
        Regular Visitor

        I'm trying to control the way data is summarized in a Power BI report. My data looks something like this:

        CustomerProjectTeam MemberProject PriceWork Hours
        Cust1Project 1TM 11000010
        Cust1Project 1TM 21000020
        Cust1Project 1TM 31000030
        Cust1Project 2TM 150005
        Cust1Project 2TM 2500010
        Cust1Project 2TM 3500015
        Cust 2Project 4TM 545000200

         

        In the report, I have summarization at the customer and project levels, summing the project price and work hours values. The project prices, as you'd imagine, shouldn't be added together until the summary at the customer level. The work hours should be summed at both the project and customer level so that I get a report that looks something like this?

         

        CustomerProjectTeam MemberProject PriceWork Hours
        Cust 1 Total  1500090
         Project 1 Total 1000060
        Cust1Project 1TM 11000010
        Cust1Project 1TM 21000020
        Cust1Project 1TM 31000030
         Project 2 Total 500030
        Cust1Project 2TM 150005
        Cust1Project 2TM 2500010
        Cust1Project 2TM 3500015
        Cust 2 Total  45000200
         Project 2 Total 45000200
        Cust 2Project 4TM 545000200

         

        I gather that there's a way to do this with DAX by defining the measures properly but I could use some help figuring out what that is.