Tools Advisor | Power BI

Refining Purchases Count Measure Excluding Riesling

Enhancing accuracy by adjusting measure logic to exclude Riesling purchases between March-May 2024 using COUNTAX function in DAX, optimizing performance and ensuring correct filtering.


Empty image or helper icon

This Query related with thread "Refining Purchases Count Measure Excluding Riesling "

Prompt

I’m trying to create a measure that will show the count of purchases excluding a certain product (in this case it’s the wine Riesling) between a certain period in this case the table is called FY period and it is written as 202403 for March 2024, 202305 for May 2024 etc.

However the number doesn’t seem to be accurate when I drag the measure into a card.

Can anybody help me to see where I am going wrong with my measure?

The measure code is below:

Sales excluding Riesling between March and May =
CALCULATE(
COUNTROWS(‘Module Sales with Inventory’),
EXCEPT(
ALL(‘Module Sales with Inventory’),
FILTER(
‘Module Sales with Inventory’,
RELATED(‘Dimension Item’[description]) = “Riesling”
)
),
FILTER(
‘Dimension Period’,
VALUE(‘Dimension Period’[fyperiod]) >= 202303 && VALUE(‘Dimension Period’[fyperiod]) <= 202305
)
)

Answer

Problem Analysis

The measure provided aims to count purchases excluding a specific product (Riesling) made between March and May 2024. The issue seems to lie in the logic of the measure, affecting the accuracy of the count when visualized in Power BI.

Strategic Solution Development

  1. Refine the Filter Conditions: Adjust the measure to ensure accurate filtering based on the desired criteria.
  2. Use the COUNTAX Function: To count rows meeting the specified conditions.
  3. Optimize the Measure Logic: Simplify the logic for better performance and accuracy.

Comprehensive Advice

  • Modify the measure to use the COUNTAX function alongside appropriate filters to achieve an accurate count of purchases excluding Riesling between March and May 2024.
  • Utilize the DAX functions FILTER and COUNTAX to enhance the measure's accuracy and efficiency.
  • Ensure that the logic for filtering products and periods aligns correctly with your requirements.

Code-Based Solutions

Sales excluding Riesling between March and May = 
COUNTAX(
    FILTER(
        'Module Sales with Inventory',
        'Dimension Item'[description] <> "Riesling" &&
        'Dimension Period'[fyperiod] >= 202303 && 'Dimension Period'[fyperiod] <= 202305
    ),
    1
)

Detailed Explanations

  • The revised code uses COUNTAX in combination with FILTER to accurately count rows based on the specified conditions.
  • It filters the dataset for purchases excluding Riesling between March and May 2024, ensuring the accuracy of the count.
  • By simplifying the measure's logic and utilizing appropriate DAX functions, you can improve its performance and reliability.

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

Enhancing accuracy by adjusting measure logic to exclude Riesling purchases between March-May 2024 using COUNTAX function in DAX, optimizing performance and ensuring correct filtering.