Forum Discussion
Calculated Table causes performance issue and dataset refresh fails
- Feb 20, 2024
First few general notes. You didn't disable Time Intelligence for the model
as result you have a lot of generated hidden date tables
which could significantly decrease of overall performance. Better to mark Calendar table as date one and use only it disabling Time Intelligence. However, on this step that could crash the model, if to do that when step by step.
Next, if you don't really need datetime use date Date data type instead. For your initial calculated table that decreases the refresh time on about 30%. Also, depends on how critical the precision is, better to use Fixed decimal number instead of Decimal number data type.
Back to calculated table I don't think we may avoid it. But the may decrease it a bit. First, creating explicit measures
which are obvious, like
0 number of Credits = CALCULATE( COUNTROWS(Data), Data[Source] = "Invoice", Data[Invoice / Credit] < 0 )With that calculated table could be
CALCULATETABLE( DISTINCT( SELECTCOLUMNS( Data, Data[DBName-Point_Id], Data[Date] ) ), Data[Source] = "Invoice" )with adding to it calculating column as in your variant
IF( [0 Number of Invoices] > 1 && [0 Number of Invoices] > [0 Number of Credits], "Multiple Invoices", IF( [0 Number of Credits] > [0 Number of Invoices] && [0 Net Cost] <> 0, "Multiple Credits", IF( ISEVEN( [0 Invoice Issue] ) && [0 Net Cost] <> 0, "Invoice-Credit Value Mismatch", IF( [0 Number of Credits] = [0 Number of Invoices] && [0 Net Cost] = 0, "Credit Cancels Invoice", BLANK( ) ) ) ) )Alternatively we may create the table with Status column from scratch
VAR selectData = DISTINCT( SELECTCOLUMNS( Data, Data[DBName-Point_Id], Data[Date] ) ) RETURN CALCULATETABLE( ADDCOLUMNS( selectData, "Status", SWITCH( TRUE( ), [0 Number of Invoices] > 1 && [0 Number of Invoices] > [0 Number of Credits], "Multiple Invoices", [0 Number of Credits] > [0 Number of Invoices] && [0 Net Cost] <> 0, "Multiple Credits", ISEVEN( [0 Invoice Issue] ) && [0 Net Cost] <> 0, "Invoice-Credit Value Mismatch", [0 Number of Credits] = [0 Number of Invoices] && [0 Net Cost] = 0, "Credit Cancels Invoice", BLANK( ) ) ), Data[Source] = "Invoice" )Both are in the model, I added only this visuals for them
DAX Studio shows bit better performance, but not critically. On the other hand on my PC all 3 variants work.
File is here TechComm - OneDrive (live.com)
First few general notes. You didn't disable Time Intelligence for the model
as result you have a lot of generated hidden date tables
which could significantly decrease of overall performance. Better to mark Calendar table as date one and use only it disabling Time Intelligence. However, on this step that could crash the model, if to do that when step by step.
Next, if you don't really need datetime use date Date data type instead. For your initial calculated table that decreases the refresh time on about 30%. Also, depends on how critical the precision is, better to use Fixed decimal number instead of Decimal number data type.
Back to calculated table I don't think we may avoid it. But the may decrease it a bit. First, creating explicit measures
which are obvious, like
0 number of Credits = CALCULATE(
COUNTROWS(Data),
Data[Source] = "Invoice",
Data[Invoice / Credit] < 0
)
With that calculated table could be
CALCULATETABLE(
DISTINCT(
SELECTCOLUMNS( Data, Data[DBName-Point_Id], Data[Date] )
),
Data[Source] = "Invoice"
)
with adding to it calculating column as in your variant
IF(
[0 Number of Invoices] > 1
&& [0 Number of Invoices]
> [0 Number of Credits],
"Multiple Invoices",
IF(
[0 Number of Credits]
> [0 Number of Invoices]
&& [0 Net Cost] <> 0,
"Multiple Credits",
IF(
ISEVEN( [0 Invoice Issue] )
&& [0 Net Cost] <> 0,
"Invoice-Credit Value Mismatch",
IF(
[0 Number of Credits]
= [0 Number of Invoices]
&& [0 Net Cost] = 0,
"Credit Cancels Invoice",
BLANK( )
)
)
)
)
Alternatively we may create the table with Status column from scratch
VAR selectData =
DISTINCT(
SELECTCOLUMNS( Data, Data[DBName-Point_Id], Data[Date] )
)
RETURN
CALCULATETABLE(
ADDCOLUMNS(
selectData,
"Status",
SWITCH(
TRUE( ),
[0 Number of Invoices] > 1
&& [0 Number of Invoices] > [0 Number of Credits], "Multiple Invoices",
[0 Number of Credits] > [0 Number of Invoices]
&& [0 Net Cost] <> 0, "Multiple Credits",
ISEVEN( [0 Invoice Issue] ) && [0 Net Cost] <> 0, "Invoice-Credit Value Mismatch",
[0 Number of Credits] = [0 Number of Invoices]
&& [0 Net Cost] = 0, "Credit Cancels Invoice",
BLANK( )
)
),
Data[Source] = "Invoice"
)
Both are in the model, I added only this visuals for them
DAX Studio shows bit better performance, but not critically. On the other hand on my PC all 3 variants work.
File is here TechComm - OneDrive (live.com)