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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
CiuCiCiao
Helper I
Helper I

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

1 ACCEPTED SOLUTION
TheOckieMofo
Resolver II
Resolver II

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.

View solution in original post

7 REPLIES 7
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])

 

 

 

@AnonymousI went through something that looks worst 😄

 

=
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

TheOckieMofo
Resolver II
Resolver II

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.

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

 

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.

Greg_Deckler
Super User
Super User

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


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.