Forum Discussion

CiuCiCiao's avatar
CiuCiCiao
Helper I
9 years ago
Solved

Assistance needed with formula

Hi Guys,

As in the table below I have Customer ID for each Service and ha date.

I concatenate Customer ID and Date to have a unique Key of Entry / Admission.

I need to spread Front Office cost by entry instead of number of service, so what I need is a formula that gives me the output of the table below for column "Entry".

CustomerDateServiceKeyEntry
128/07/2017A1429440,25
128/07/2017B1429440,25
128/07/2017E1429440,25
128/07/2017F1429440,25
228/07/2017D2429440,333333
228/07/2017B2429440,333333
228/07/2017F2429440,333333
328/07/2017F3429440,5
328/07/2017A3429440,5
428/07/2017C4429441
129/07/2017B1429450,5
129/07/2017D1429450,5
329/07/2017A3429451
429/07/2017F4429450,5
429/07/2017E4429450,5

Any hint how can i manage this in DAX?

Thanks

  • You need to get familiar with the early function. It's one of those functions that I'm not totally sure why it works, I just know it does. So let's learn by doing.

     

    So you can use this function to create a count of the rows that have each unique key. The syntax would be:

     

    =CALCULATE(COUNTA([KEY]),FILTER('TABLENAME','TABLENAME'[KEY]=EARLIER('TABLENAME'[KEY])))

     

    This would be the denominator in your equation, so you could just put a "1/" in front of the above equation to get your proper value.

     

    That should work for you. Let me know.

7 Replies

  • You need to get familiar with the early function. It's one of those functions that I'm not totally sure why it works, I just know it does. So let's learn by doing.

     

    So you can use this function to create a count of the rows that have each unique key. The syntax would be:

     

    =CALCULATE(COUNTA([KEY]),FILTER('TABLENAME','TABLENAME'[KEY]=EARLIER('TABLENAME'[KEY])))

     

    This would be the denominator in your equation, so you could just put a "1/" in front of the above equation to get your proper value.

     

    That should work for you. Let me know.

    • CiuCiCiao's avatar
      CiuCiCiao
      Helper I

      Works good! Thanks!

      About the earlier function, I am using it in the same model inside a filter, but still I can't get why...

      Link to the discussion

       

      • TheOckieMofo's avatar
        TheOckieMofo
        Resolver II

        Yeah, the EARLIER function is just one of those things. I always liken it to Calculus. I don't know how derivates/integrals work, but I assume the French guys in the 1700s got it right, so I use it. The only thing we need to know is when to apply it.

         

        Anytime you need to compare rows instead of compare columns, you're probably going to use the Earlier function at some point.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Get the overall count by key. So for Customer 1, this number would be 4:

     

    OverallCountByKey:=CALCULATE(count(Sheet1[Key]),ALLEXCEPT(Sheet1,Sheet1[Key]))

     

    Then divide the count of key by this new measure:

     

    % of Total:=DIVIDE(Count(Sheet1[Key]),[OverallCountByKey])

     

     

     

    • CiuCiCiao's avatar
      CiuCiCiao
      Helper I

      AnonymousI went through something that looks worst :D

       

      =
      1
          / CALCULATE (
              COUNTA ( [KEY] ),
              FILTER ( 'TABLENAME', 'TABLENAME'[KEY] = EARLIER ( 'TABLENAME'[KEY] ) )
          )
          / SUMX (
              'TABLENAME',
              1
                  / CALCULATE (
                      COUNTA ( [KEY] ),
                      FILTER ( 'TABLENAME', 'TABLENAME'[KEY] = EARLIER ( 'TABLENAME'[KEY] ) )
                  )
          )

      This works for me though! I'll try your formula Monday since it looks cleaner!

      Thanks

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    I'm totally not following this. Perhaps paste in your source data and what you want the result to look like?

    • CiuCiCiao's avatar
      CiuCiCiao
      Helper I

      Greg_DecklerI am sorry for my inaccuracy.

      For all the column "Key" I need a formula to divide 1 by the number of each duplicate.

      E.g. for: 142944  =(1/4)

       

      KeyEntryFormula
      1429440,251/4
      1429440,251/4
      1429440,251/4
      1429440,251/4
      2429440,3333331/3
      2429440,3333331/3
      2429440,3333331/3
      3429440,51/2
      3429440,51/2
      44294411/1

       

      Hope now is clearer.

      Thanks