Forum Discussion
DistinctCount - aggregation - not working - I'm lost
Hi there!
I've been struggling with distinctcount per transaction_id when trying to use an agg.table.
It's been more than 7 months since this issue came to light, but I cannot see a solution, and I feel pretty clueless where i'm messing it up.
It works fine when in Directquery mode as long as I don't use an agg. table, but the results take up to 30~100 seconds to complete and is not a viable solution long term.
I set ut the sql table as an agg as well, so have access to both Powerbi, and SQL server.
The transaction_id is unique to each complete transaction, and we have around 50 million per year (it's around 16-17 digits long)
The fact table consists of transactions rows with a 1-10 (lines or products) per transaction_id
Agg table sql side:
...
agg_final as (
select
store_number,
product_id,
cal_date,
count(distinct(transaction_id)) as transaction_id
sum(sales_amount) as sales_amount
1 as fusion_key
count (*) as count_rows
from fact_sales
Group by
store_number,
product_id,
cal_date
)
The dax i'm using is a simple calculate(distinctcount(transaction_id),TREATAS{1}, Fact_table[Fusion_key]))
The agg does get a match in dax studio, but the results are pretty wrong when using the agg table, Works perfect when I don't use agg. table.
Also using the product_name in a matrix.
The fusionkey does not change anything in the dax measure - seem irrelevant as GuyInaCube video tried to explain.
So it's either a sql side error or powerbi, unsure where to even debug.
Thanks for your time.
2 Replies
- AnushaSriResolver II
Hi,
1. Have you had a look into the data types of Fusion_key in both fact and agg tables? - some times creating a relation on different data types might create issue.2. On your Red Arrow you are pointing at Cout of transaction id with actual transaction id , could not understand much, but if you are trying to create a relationship then its not a valid realation as one is id and one is count.
- AnonymousNot applicable
Hi Valentb ,
Can you please share a pbix or some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.
How to Get Your Question Answered Quickly
Regards,
Xiaoxin Sheng