Monday, February 26, 2024

Benford's Law in M for Power BI



On first glance, this seems a little raw, with several steps that are wholly unnecessary.  However, it works.  Hopefully, I can revisit this and clean it up a little.

Begin in Power BI, transforming the data.  Do not rename columns, until specified.
  1. Add Column -> First Characters
    1. Extract the first digit of the numbers to be analyzed.
  2. Sort Lowest to Highest
  3. Click Column Title for First Characters Column
    1. Add as New Query, which will appear as a list.
    2. Convert List to Table [COLUMN1]
  4. Sort [COLUMN1] Lowest to Highest
  5. Group By (no change to default screen)
  6. Sort [COLUMN1] again, if needed to order
  7. Create Index Column beginning with 1
  8. Create Custom Column [COLUMN]
    1. List.Sum(List.Range(#"Added Index"[Count],0,[Index]))
  9. Create Custom Column [COLUMN.1]
    1. [Count]/List.Sum(#"Added Custom"[Count])
  10. Change [COLUMN.1] to %
  11. Add Column from Examples for Benford’s Law [COLUMN.2]
    1. 0.301
    2. 0.176
    3. 0.125
    4. 0.097
    5. 0.079
    6. 0.067
    7. 0.058
    8. 0.051
    9. 0.046
  12. Change [COLUMN.2] to %
  13. Rename
    1. [COLUMN.1] = Actual %
    2. [COLUMN.2] = Benford %
  14. Graph


The above was transcribed from the following YouTube video:


No comments:

Post a Comment

Leave your thoughts here. You gotta have a Google account though.

Popular Variations