Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hi Power BI Community,
I’m currently working on a dataset with two tables, Raw_Data 1 and Raw_Data 2, which contain the following columns:
For the purchase order and line number, the Need By Date and Open Qty values can either be the same or different between these tables.
I’ve created measures to filter data based on user-selected dates and compare the Need By Date and Open Qty values from both tables. These comparison measures work fine in a table visual but I’m unable to use them effectively in other visuals, such as cards or bar charts.
Raw_Data 1:
Raw_Data 2:
Date Comparison:
Qty Comparison:
These measures work perfectly in a table visual, showing row-wise comparisons for Need By Date and Open Qty. However, I cannot use them in visuals like cards or bar charts since they rely on specific row context provided by the table visual.
I’ve considered creating calculated columns for comparison, but this approach requires using aggregation functions (e.g., MIN), which won’t work for scenarios where multiple dates exist for the same purchase order and line number.
Here’s an example of a calculated column I tried (but don’t want):
This is problematic because aggregating the dates (MIN, MAX) loses the granularity I need.
How can I make my comparison measures (Date Comparison and Qty Comparison) usable in visuals like cards and bar charts? Is there a way to summarize or aggregate these measures meaningfully while maintaining their row-level logic?
Any suggestions or best practices would be greatly appreciated!
Thank you!
Solved! Go to Solution.
Hi @Hashmeet ,
To solve the issue of using your comparison measures in visuals like cards and bar charts, we need to adjust your DAX formulas so that they can aggregate meaningful results across the entire dataset. The current setup works well in a table visual because it relies on row context to evaluate the differences between Raw_Data 1 and Raw_Data 2. However, when you want to use these measures in summary visuals, you need to aggregate the comparison outcomes meaningfully without losing granularity.
The key is to convert your comparison results into numeric values that can be counted or aggregated, rather than returning text outputs like "Dates Match" or "Qty Match." By doing this, you can create summary measures that count the number of matches, mismatches, or changes across the entire dataset.
First, modify your Date Comparison and Qty Comparison measures to return numeric values. For Date Comparison, the measure can be rewritten as follows:
Date Comparison Numeric =
VAR d1 = [Need By Date First]
VAR d2 = [Need By Date Second]
RETURN
SWITCH(
TRUE(),
ISBLANK(d1) && ISBLANK(d2), 0, // No Date Present
NOT ISBLANK(d1) && ISBLANK(d2), 1, // New Date Added
ISBLANK(d1) && NOT ISBLANK(d2), 2, // Date Removed
d1 = d2, 3, // Dates Match
4 // Dates Don't Match
)
Similarly, modify the Qty Comparison measure to return numeric values:
Qty Comparison Numeric =
VAR q1 = [Open Qty First]
VAR q2 = [Open Qty Second]
RETURN
SWITCH(
TRUE(),
ISBLANK(q1) && ISBLANK(q2), 0, // No Qty Present
NOT ISBLANK(q1) && ISBLANK(q2), 1, // New Qty Added
ISBLANK(q1) && NOT ISBLANK(q2), 2, // Qty Removed
q1 = q2, 3, // Qty Match
4 // Qty Don't Match
)
Once these numeric measures are created, you can aggregate them across the dataset to show meaningful counts in visuals. For example, you can create a measure to count how many times the dates match between the two tables:
Count of Dates Match =
CALCULATE(
COUNTROWS('Raw_Data 1'),
[Date Comparison Numeric] = 3
)
Similarly, create a measure to count how many times the quantities match:
Count of Qty Match =
CALCULATE(
COUNTROWS('Raw_Data 1'),
[Qty Comparison Numeric] = 3
)
You can also create measures to count other outcomes, such as new dates added or dates removed. The aggregation logic can be extended further by calculating percentages. For example, to calculate the percentage of matching dates:
Date Match Percentage =
DIVIDE(
[Count of Dates Match],
COUNTROWS('Raw_Data 1'),
0
)
If you want to visualize the different comparison outcomes in a bar chart, create a measure that returns the category label based on the numeric value from your comparison measure. For example, to categorize the date comparison results:
Date Comparison Categories =
SWITCH(
TRUE(),
[Date Comparison Numeric] = 1, "New Date Added",
[Date Comparison Numeric] = 2, "Date Removed",
[Date Comparison Numeric] = 3, "Dates Match",
[Date Comparison Numeric] = 4, "Dates Don't Match",
"No Date Present"
)
This measure can be used as a legend or axis in a bar chart to display the distribution of comparison outcomes across the dataset.
By using this approach, you retain the row-level logic in your comparisons while enabling meaningful aggregation for summary visuals. You can count the occurrences of each comparison outcome and visualize them effectively in cards, bar charts, and other visuals. This ensures that your comparison logic is not lost when you switch from a table visual to summary visuals, providing a more comprehensive view of your data comparisons.
Best regards,
Hi @Hashmeet
Thank you DataNinja777 for your wonderful reply.
May I ask if DataNinja777's reply helped you solve your problem? If so please consider accepting his reply as a solution, it will make it easier for other users with similar problems to find a solution.
Best Regards,
Jarvis Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Hashmeet ,
To solve the issue of using your comparison measures in visuals like cards and bar charts, we need to adjust your DAX formulas so that they can aggregate meaningful results across the entire dataset. The current setup works well in a table visual because it relies on row context to evaluate the differences between Raw_Data 1 and Raw_Data 2. However, when you want to use these measures in summary visuals, you need to aggregate the comparison outcomes meaningfully without losing granularity.
The key is to convert your comparison results into numeric values that can be counted or aggregated, rather than returning text outputs like "Dates Match" or "Qty Match." By doing this, you can create summary measures that count the number of matches, mismatches, or changes across the entire dataset.
First, modify your Date Comparison and Qty Comparison measures to return numeric values. For Date Comparison, the measure can be rewritten as follows:
Date Comparison Numeric =
VAR d1 = [Need By Date First]
VAR d2 = [Need By Date Second]
RETURN
SWITCH(
TRUE(),
ISBLANK(d1) && ISBLANK(d2), 0, // No Date Present
NOT ISBLANK(d1) && ISBLANK(d2), 1, // New Date Added
ISBLANK(d1) && NOT ISBLANK(d2), 2, // Date Removed
d1 = d2, 3, // Dates Match
4 // Dates Don't Match
)
Similarly, modify the Qty Comparison measure to return numeric values:
Qty Comparison Numeric =
VAR q1 = [Open Qty First]
VAR q2 = [Open Qty Second]
RETURN
SWITCH(
TRUE(),
ISBLANK(q1) && ISBLANK(q2), 0, // No Qty Present
NOT ISBLANK(q1) && ISBLANK(q2), 1, // New Qty Added
ISBLANK(q1) && NOT ISBLANK(q2), 2, // Qty Removed
q1 = q2, 3, // Qty Match
4 // Qty Don't Match
)
Once these numeric measures are created, you can aggregate them across the dataset to show meaningful counts in visuals. For example, you can create a measure to count how many times the dates match between the two tables:
Count of Dates Match =
CALCULATE(
COUNTROWS('Raw_Data 1'),
[Date Comparison Numeric] = 3
)
Similarly, create a measure to count how many times the quantities match:
Count of Qty Match =
CALCULATE(
COUNTROWS('Raw_Data 1'),
[Qty Comparison Numeric] = 3
)
You can also create measures to count other outcomes, such as new dates added or dates removed. The aggregation logic can be extended further by calculating percentages. For example, to calculate the percentage of matching dates:
Date Match Percentage =
DIVIDE(
[Count of Dates Match],
COUNTROWS('Raw_Data 1'),
0
)
If you want to visualize the different comparison outcomes in a bar chart, create a measure that returns the category label based on the numeric value from your comparison measure. For example, to categorize the date comparison results:
Date Comparison Categories =
SWITCH(
TRUE(),
[Date Comparison Numeric] = 1, "New Date Added",
[Date Comparison Numeric] = 2, "Date Removed",
[Date Comparison Numeric] = 3, "Dates Match",
[Date Comparison Numeric] = 4, "Dates Don't Match",
"No Date Present"
)
This measure can be used as a legend or axis in a bar chart to display the distribution of comparison outcomes across the dataset.
By using this approach, you retain the row-level logic in your comparisons while enabling meaningful aggregation for summary visuals. You can count the occurrences of each comparison outcome and visualize them effectively in cards, bar charts, and other visuals. This ensures that your comparison logic is not lost when you switch from a table visual to summary visuals, providing a more comprehensive view of your data comparisons.
Best regards,
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
145 | |
87 | |
66 | |
51 | |
45 |
User | Count |
---|---|
215 | |
90 | |
83 | |
66 | |
58 |