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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Evandam
Helper II
Helper II

devide by count of duplicate numbers

Hi,

 

i need some help with a calculation i would like to perform.

 

invoice numbersub numberinvoice total amountsub amount
13891017,4257,388
13892017,42537
13401119,5005,000
13401139,5004,500

 

when i make a visual and insert the invoice number and invoice amount as value, the value is summarized so the outcome is like this:

invoice numberinvoice amount
1389(7.425*2) = 14,850
1340(9,500*2_ = 20,000

 

As you can imagine this is not correct.

i needs to be: 

invoice numberinvoice amount
13897,425
13409,500

 

can this be done in query editor by sum the total amount per invoice number and than divde that by counting the amount of times each invoice number occurs? 

thanks in advance

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

A) If you need this in Power Query, remove the sub number & sub amount columns, select the Invoice number column and remove the duplicate rows:

let
  Source = Table.FromRows(
    Json.Document(
      Binary.Decompress(
        Binary.FromText(
          "VcvBDQAhCETRXjjPAQQi1mLov40VY8x64Ye8zJwkGoNAwrJuhzXf1QhKXG4Paz9mXFMpG3Cuz8GrD+uPbTfzAw==",
          BinaryEncoding.Base64
        ),
        Compression.Deflate
      )
    ),
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table [
        #"invoice number" = _t,
        #"sub number" = _t,
        #"invoice total amount" = _t,
        #"sub amount" = _t
      ]
  ),
  #"Replaced Value" = Table.ReplaceValue(
    Source,
    ",",
    ".",
    Replacer.ReplaceText,
    {"invoice total amount", "sub amount"}
  ),
  #"Changed Type" = Table.TransformColumnTypes(
    #"Replaced Value",
    {{"invoice total amount", type number}, {"sub amount", type number}}
  ),
  #"Removed Other Columns" = Table.SelectColumns(
    #"Changed Type",
    {"invoice number", "invoice total amount"}
  ),
  #"Removed Duplicates" = Table.Distinct(#"Removed Other Columns", {"invoice number"})
in
  #"Removed Duplicates"

duplicates.png

B) If you need this as a measure, use a simple AVERAGE function:

Average = 
AVERAGE('Table'[invoice total amount])

measure.png

 

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

2 REPLIES 2
PaulDBrown
Community Champion
Community Champion

A) If you need this in Power Query, remove the sub number & sub amount columns, select the Invoice number column and remove the duplicate rows:

let
  Source = Table.FromRows(
    Json.Document(
      Binary.Decompress(
        Binary.FromText(
          "VcvBDQAhCETRXjjPAQQi1mLov40VY8x64Ye8zJwkGoNAwrJuhzXf1QhKXG4Paz9mXFMpG3Cuz8GrD+uPbTfzAw==",
          BinaryEncoding.Base64
        ),
        Compression.Deflate
      )
    ),
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table [
        #"invoice number" = _t,
        #"sub number" = _t,
        #"invoice total amount" = _t,
        #"sub amount" = _t
      ]
  ),
  #"Replaced Value" = Table.ReplaceValue(
    Source,
    ",",
    ".",
    Replacer.ReplaceText,
    {"invoice total amount", "sub amount"}
  ),
  #"Changed Type" = Table.TransformColumnTypes(
    #"Replaced Value",
    {{"invoice total amount", type number}, {"sub amount", type number}}
  ),
  #"Removed Other Columns" = Table.SelectColumns(
    #"Changed Type",
    {"invoice number", "invoice total amount"}
  ),
  #"Removed Duplicates" = Table.Distinct(#"Removed Other Columns", {"invoice number"})
in
  #"Removed Duplicates"

duplicates.png

B) If you need this as a measure, use a simple AVERAGE function:

Average = 
AVERAGE('Table'[invoice total amount])

measure.png

 

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Fowmy
Super User
Super User

@Evandam 

Right click on the Invoice Amount and Choose MAximum 

Fowmy_1-1661942749417.png

or

Create a new measure to get the maximum value as follows:

 

Invoice Amount Max = MAX('TableName'[Invoice Amount])

 

 




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.