Logic Visualizer | DAX

Calculation of New Customers Measure

This code calculates a measure called NewCustomers by performing various operations on the Sales dataset. It filters the dataset based on specific criteria, calculates the distinct count of CustomerID, and applies additional filters on SalesDate and...


Empty image or helper icon

This Query related with thread ""

Prompt

// Creating a measure for New Customers
NewCustomers :=
CALCULATE (
    DISTINCTCOUNT ( Sales[CustomerID] ), // Counting unique customers
    FILTER ( // Filtering the Sales table
        ALL ( Sales ), // Considering all rows irrespective of an existing filter 
        Sales[CustomerID] // Sales records for a Certain Customer   
        IN CALCULATETABLE ( // Creating a derived table 
            VALUES ( Sales[CustomerID] ), // Unique Customers
            FILTER ( 
                ALL ( Sales[Date] ), // Taking all dates ignoring the existing filter
                Sales[Date] <= MAX ( Sales[Date]) // Taking dates less than or equal to the maximum date which is the considered period (month and year context)
            ),
            Sales[SalesAmount] // Sales must be greater than zero
        )
    )
)

Answer

Here is the visual representation in form of a pseudocode:

START
    DEFINE NewCustomers as
        DISTINCTCOUNT of Sales[CustomerID]
            FILTER the Sales table with
                Sales[CustomerID] is IN
                    CALCULATETABLE of 
                        VALUES of Sales[CustomerID]
                        FILTER the sales date with
                            Sales date <= MAXIMUM Sales date
                            Sales amount > 0
END

The flowchart or logic diagram can be represented as:

Start
↓
Define measure: NewCustomers
↓
Calculate DISTINCTCOUNT of Sales[CustomerID]
↓
Filter(Sales) - based on criteria
|
→ CustomerID IN
|     ↓
|   Create derived table using CALCULATETABLE
|     ↓
|   Take unique VALUES of CustomerID
|     ↓
|   Filter(All(SalesDate)) - based on criteria
|     ↓
|   Only take SalesDates <= Max SalesDate
|     ↓
|   Include only cases where SalesAmount > 0
↓
End

This visual representation clearly breaks down each section of the code, starting from the initiation of defining the measure NewCustomers, then moving through each filter and operation, and finally ending the measure's definition.

  • The pseudo code summarizes each step of the logic in the actual code.
  • The flowchart provides a visual structure that shows the overall flow of logic and operations in the original code. It shows how each operation is nested within another operation, and how they all contribute to the final outcome which is the NewCustomers measure.

Remember that this kind of complex operations might be better understood by experimenting and using various tools available at Enterprise DNA Platform, such as the Power BI and DAX courses.

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

The purpose of this code is to calculate a measure called NewCustomers using the Sales dataset. The measure represents the number of new customers based on specific criteria. The code starts by defining the measure and then proceeds to filter the Sales dataset.

In the code, distinct count is calculated for the CustomerID column after applying filters. The filters are applied using the CALCULATETABLE function, which creates a derived table based on specific criteria. The derived table includes only unique values of CustomerID and applies additional filters on SalesDate and SalesAmount.

The flowchart provides a visual representation of the code's logic, showing how each operation is nested within another operation. This helps to understand the overall flow of the code and how each step contributes to the final outcome.

By using both pseudocode and a flowchart, the code's logic is clearly explained and visualized, making it easier for users to understand and interpret the purpose and functionality of the NewCustomers measure calculation.