Forum Discussion
Compare Cumulative Count on Dimension Table Each Year vs Count Distinct Column on Fact Table by Year
Hi Experts,
This is my relationship table design :
note :
fact table : vDataInvoiceBUC
dimension table : vMasterCalender, vMasterCustomer
The main goal is calculate the percentage of count distinct column on vDataInvoiceBUC per year (dateinvoice of customerid column) vs count of cumulative vMasterCustomer per year (user input date of customerid), with the dimension is by year.
The DAX below is used to calculation.
vDataInvoiceBUC :
_DATEYEAR = YEAR(vDataInvoiceBUC[DATEINVOICE])
_CUSTOMER_COUNTDISTINCT = CALCULATE(DISTINCTCOUNT(vDataInvoiceBUC[CUSTOMERID]))
_CUSTOMER_COUNTDISTINCT_BYYEARCUSTOMER =
CALCULATE(
[_CUSTOMER_COUNTDISTINCT],
FILTER(vDataInvoiceBUC,year(vDataInvoiceBUC[DATEINVOICE]) IN VALUES(vMasterCustomer[_YEAR]))
)
vMasterCustomer :
_YEAR = IF(LEFT(vMasterCustomer[CUSTOMERID],2)="KE" || LEFT(vMasterCustomer[CUSTOMERID],2) = "MA", 2017, LEFT(vMasterCustomer[CUSTOMERID],2)+2000)
_CUSTOMERID_COUNT_COA =
CALCULATE(COUNT(vMasterCustomer[CUSTOMERID]),vMasterCustomer[CUSTOMERTYPE]="COATING")
_CUSTOMERID_COUNT_COA_SUM =
VAR CurrentProduct = MAX(vMasterCustomer[_YEAR])
RETURN
SUMX(
FILTER(
SUMMARIZE(
ALLSELECTED(vMasterCustomer),vMasterCustomer[_YEAR], "COUNTCUST", [_CUSTOMERID_COUNT_COA], "MAXYEAR", vMasterCustomer[_YEAR]
),
[MAXYEAR] <= CurrentProduct
),
[COUNTCUST]
)
And then I create matrix chart with vMasterCustomer._YEAR as rows
The _CUSTOMERID_COUNT_COA and _CUSTOMERID_COUNT_COA_SUM column show the correct value, but not _CUSTOMER_COUNTDISTINCT and _CUSTOMER_COUNTDISTINCT_BYYEARCUSTOMER column. The _CUSTOMER_COUNTDISTINCT column is calculated the customerid based on vMasterCustomer._YEAR column, not based on vDataInvoiceBUC._DATEYEAR .
This is what I expected show for those 2 column :
The matrix chart above is done by using vDataInvoiceBUC._DATEYEAR as rows.
So, the main goal is show as below and I can do divide calculation between _CUSTOMERID_COUNT_COA vs _CUSTOMERID_COUNT_COA_SUM :
Please see the attachment for the data example :
https://drive.google.com/drive/folders/1g_3yBqaQxZ3WfwCGzp_xIE21uth7SUso?usp=sharing
Thank you for your help
Sincerely,
Oviedityanto
Hmmm I've found the solution.
The solution is create new table and join between vMasterCustomer._YEAR to vDataInvoiceBUC_Customer_Count._DATEYEAR.Below is the table design.
This is DAX for new table
vDataInvoiceBUC_Customer_Count = SUMMARIZE(vDataInvoiceBUC,vDataInvoiceBUC[_DATEYEAR],"COUNTCUST",DISTINCTCOUNT(vDataInvoiceBUC[CUSTOMERID]))
And below is the matrix chart
1 Reply
- OviedityantoFrequent Visitor
Hmmm I've found the solution.
The solution is create new table and join between vMasterCustomer._YEAR to vDataInvoiceBUC_Customer_Count._DATEYEAR.Below is the table design.
This is DAX for new table
vDataInvoiceBUC_Customer_Count = SUMMARIZE(vDataInvoiceBUC,vDataInvoiceBUC[_DATEYEAR],"COUNTCUST",DISTINCTCOUNT(vDataInvoiceBUC[CUSTOMERID]))
And below is the matrix chart