Code Generator | DAX

DAX Code for Distinct Count of Records with Blank Payment Date and "SW...

This DAX code calculates a distinct count measure for records where the payment date is blank and the source is "SWIPE" in a table named 'MPOS ACCR Detail'. It can be used in Power BI to analyze customers who have performed a "SWIPE" transaction but...


Empty image or helper icon

Prompt

I need to create a measure that calculates the same thing as below BUT is counting the records where the payment date is blank #A26 Distinct ACCEPT SWIPE = 
CALCULATE(
        DISTINCTCOUNT('MPOS ACCR Detail'[Mem HH ID]),
        FILTER('MPOS ACCR Detail',
            NOT(ISBLANK('MPOS ACCR Detail'[Payment Date])) &&'MPOS ACCR Detail'[MPOS Source] = "SWIPE"))

Answer

Below is the DAX Code for your requirement:

/// 
/// Returns a distinct count measure for records where the payment date is blank.
/// 
///  Input table for the measure.
/// Column on which we are applying distinct count
/// Payment date column name which we need to check if it is blank or not
/// Source column which we need to compare against "SWIPE"
/// A new measure.
/// The function will fail if the provided column or table is not found in the model.

Distinct_NoPayDate_Swipe = 
CALCULATE(
    DISTINCTCOUNT('MPOS ACCR Detail'[Mem HH ID]),
    FILTER('MPOS ACCR Detail',
        ISBLANK('MPOS ACCR Detail'[Payment Date]) && 'MPOS ACCR Detail'[MPOS Source] = "SWIPE")
)

The above code works as follows - CALCULATE evaluates the DISTINCTCOUNT('MPOS ACCR Detail'[Mem HH ID]) measure applied to the 'MPOS ACCR Detail' table after filtering it based on two conditions specified. The FILTER function returns the requested column where the [Payment Date] column is blank, and the [MPOS Source] column equals "SWIPE".

Code Usage Example:

This code snippet could be handy in scenarios where we want to analyze the behavior of customers who did the "SWIPE" but haven't given the payment details yet. This can be used to focus on this particular customer segment for the follow-ups. You can use this measure with many visualizations throughout Power BI like tables, cards, line charts, bar charts, etc. depending upon other measures you are plotting together with this.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

This DAX code snippet calculates a distinct count measure for records where the payment date is blank and the source is "SWIPE". It is useful for analyzing the behavior of customers who have performed a "SWIPE" but haven't given the payment details yet. The code can be used in Power BI as a measure to create various visualizations such as tables, cards, line charts, and bar charts. By focusing on this customer segment, follow-ups can be carried out effectively.