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
jspitler
Regular Visitor

Need a measure that calclulates a total by group by

Hey Everyone

 

I am new to PBI.  I need a measure that caculates a total by grouping by two columns in the table.  I have one but but it doesn't give me the correct restults.

 

Table Name = MonthlyInvoice
+-----+-----------+-----+

| CID | Month     | Amt |
+-----+-----------+-----+

| 101 | 1/01/2020 | 15  |

| 101 | 1/01/2020 | 20  |

| 101 | 1/01/2020 | 25  |

| 101 | 2/01/2020 | 35  |

| 101 | 2/01/2020 | 40  |

| 101 | 2/01/2020 | 45  |

| 201 | 1/01/2020 | 35  |

| 201 | 1/01/2020 | 40  |

| 201 | 1/01/2020 | 55  |

| 201 | 2/01/2020 | 65  |

| 201 | 2/01/2020 | 70  |

| 201 | 2/01/2020 | 75  |
+-----+-----------+-----+

 

The goal is a measure that calculates the total per ClientID/Month for Amount
+-----+-----------+-----+-----+
| CID | Month     | Amt | Tot |
+-----+-----------+-----+-----+

| 101 | 1/01/2020 | 15  | 60  |

| 101 | 1/01/2020 | 20  | 60  |

| 101 | 1/01/2020 | 25  | 60  |

| 101 | 2/01/2020 | 35  | 120 |

| 101 | 2/01/2020 | 40  | 120 |

| 101 | 2/01/2020 | 45  | 120 |

| 201 | 1/01/2020 | 35  | 130 |

| 201 | 1/01/2020 | 40  | 130 |

| 201 | 1/01/2020 | 55  | 130 |

| 201 | 2/01/2020 | 65  | 133 |

| 201 | 2/01/2020 | 70  | 133 |

| 201 | 3/01/2020 | 75  | 75  |
+-----+-----------+-----+-----+

 

I tried using these two, however I am clearing not getting it.

 

TotSum = sum('DW f_Inv'[amt])
 
Tot = SUMX(
VALUES('DW f_Inv'[CID]),
CALCULATE('DW f_Inv'[TotSum], all('DW f_Inv'[Month]))
)
 
Thanks.
 

 

 

5 REPLIES 5
jspitler
Regular Visitor

Thanks for the suggestions.  I left out some important infor.  The data field that I have is not an actual date.  It's a key in the format yyyymmdd.

Hi @jspitler ,

 

Not sure what you meant by that.Best practise to have Date Fields marked as Date.

 

However, you can create a Calculated Column.

 

Tot = CALCULATE(SUM(MonthlyInvoice[Amt]),ALLEXCEPT(MonthlyInvoice,MonthlyInvoice[CID],MonthlyInvoice[Month]))
 
123.JPG1234.JPG
 
Use Don't Summarize in Amt and Sum in Tot.
 
Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!!

Hi @jspitler ,

 

Did the solution work for you.

 

Please mark as solution for other community members to benefit.

 

Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

harshnathani
Community Champion
Community Champion

Hi @jspitler ,

 

Create a Calendar Table and then link you relationship between Calendar Table and Monthly Invoice Table.

 

Post which you can just drag and Drop, the dates from the month Table and other details from the Monthly Invoice Table.

 

https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions

 

Regards,

Harsh Nathani

 

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!!

Greg_Deckler
Super User
Super User

Thinking probably something along the lines of:

 

Column =
  SUMX(
    FILTER(
      'Table',
      [Month] = EARLIER([Month]) &&
        [CID] = EARLIER([CID])
    ),
    [Amt]
  )

@ 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...

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.