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
darraghfarrell
Frequent Visitor

comparing month on month non-numerical values in a dataset

Hi all,

 

I am trying to compare this months billing values with last months billing values. So the question i am trying to answer is "How many new customers do we have this month compared to last?". What is the best approach here to make it as dynamic as possible, i.e. to make it rolling month on month? 

image.png

 

 

 

 

 

 

 

 

I am comparing the Billing Month field and has 2 months worth of data, i.e. Feb and March. Ideally what I want my answer to display is the 2 new customers, as like below and highlighted above. These are the 2 new customers.

Capture.PNG

 

 

 

Once I have this I would also like to see which customers we have lost between March and Feb i.e. as they existed in Feb but not in March. 

image.png

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @darraghfarrell ,

 

Open Query Editor, apply below changes to source table.

  1. Sort [Billing Month] ascending.
  2. Group by table based on [Billing Month].
  3. Add index column.
let
    Source = Excel.Workbook(File.Contents("C:\Users\xxxx\Desktop\Sample Data 2.xlsx"), null, true),
    Sample_2_Sheet = Source{[Item="Sample_2",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sample_2_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Billing Month", type date}, {"Customer name", type text}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Billing Month", Order.Ascending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows", {"Billing Month"}, {{"all data", each _, type table [Billing Month=date, Customer name=text]}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1),
    #"Expanded all data" = Table.ExpandTableColumn(#"Added Index", "all data", {"Customer name"}, {"all data.Customer name"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded all data",{{"all data.Customer name", "Customer name"}})
in
    #"Renamed Columns"

1.png

 

In Data view mode, create a calculated column.

Lost/New this month =
VAR isFindnextMonth =
    IF (
        LOOKUPVALUE (
            Sample_2[Customer name],
            Sample_2[Customer name], Sample_2[Customer name],
            Sample_2[Index], Sample_2[Index] + 1
        )
            = BLANK (),
        0,
        1
    )
VAR isFindpreMonth =
    IF (
        LOOKUPVALUE (
            Sample_2[Customer name],
            Sample_2[Customer name], Sample_2[Customer name],
            Sample_2[Index], Sample_2[Index] - 1
        )
            = BLANK (),
        0,
        1
    )
RETURN
    IF (
        Sample_2[Billing Month] <> MIN ( Sample_2[Billing Month] )
            && isFindpreMonth = 0,
        "New",
        IF (
            Sample_2[Billing Month] <> MAX ( Sample_2[Billing Month] )
                && isFindnextMonth = 0,
            "Lost",
            ""
        )
    )

2.png

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yulgu-msft
Employee
Employee

Hi @darraghfarrell ,

 

Open Query Editor, apply below changes to source table.

  1. Sort [Billing Month] ascending.
  2. Group by table based on [Billing Month].
  3. Add index column.
let
    Source = Excel.Workbook(File.Contents("C:\Users\xxxx\Desktop\Sample Data 2.xlsx"), null, true),
    Sample_2_Sheet = Source{[Item="Sample_2",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sample_2_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Billing Month", type date}, {"Customer name", type text}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Billing Month", Order.Ascending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows", {"Billing Month"}, {{"all data", each _, type table [Billing Month=date, Customer name=text]}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1),
    #"Expanded all data" = Table.ExpandTableColumn(#"Added Index", "all data", {"Customer name"}, {"all data.Customer name"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded all data",{{"all data.Customer name", "Customer name"}})
in
    #"Renamed Columns"

1.png

 

In Data view mode, create a calculated column.

Lost/New this month =
VAR isFindnextMonth =
    IF (
        LOOKUPVALUE (
            Sample_2[Customer name],
            Sample_2[Customer name], Sample_2[Customer name],
            Sample_2[Index], Sample_2[Index] + 1
        )
            = BLANK (),
        0,
        1
    )
VAR isFindpreMonth =
    IF (
        LOOKUPVALUE (
            Sample_2[Customer name],
            Sample_2[Customer name], Sample_2[Customer name],
            Sample_2[Index], Sample_2[Index] - 1
        )
            = BLANK (),
        0,
        1
    )
RETURN
    IF (
        Sample_2[Billing Month] <> MIN ( Sample_2[Billing Month] )
            && isFindpreMonth = 0,
        "New",
        IF (
            Sample_2[Billing Month] <> MAX ( Sample_2[Billing Month] )
                && isFindnextMonth = 0,
            "Lost",
            ""
        )
    )

2.png

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Ashish_Mathur
Super User
Super User

Hi,

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
parry2k
Super User
Super User

@darraghfarrell check this blog, hope it helps



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.