dax optimization
10 TopicsOptimize power bi by only sending queries 1 time
I have 4 measures: Sales CY = CALCULATE(SUM(FACT_Invoice[TRX Net Sales AMT]),DIM_Date[Fiscal Year] = YEAR(TODAY())) Sales PY = CALCULATE(SUM(FACT_Invoice[TRX Net Sales AMT]),DIM_Date[Fiscal Year] = YEAR(TODAY())-1) Sales YoY = VAR _Sales_CY = [Sales CY] VAR _Sales_PY = [Sales PY] RETURN _Sales_CY - _Sales_PY Sales YoY % = VAR _Sales_CY = [Sales CY] VAR _Sales_PY = [Sales PY] RETURN DIVIDE((_Sales_CY - _Sales_PY),_Sales_PY) Requirement is that I show all 4 measures in a table visual, each have to be in their own column of a visual to allow sort by all 4 columns. When I try to optimize the Dax using Dax studio I find that the YoY and YoY % measures are taking the longest naturally. All I need to do is sent two simple queries one time to the engine. Sales CY and Sales PY. From there I wish I could just use the cache to run by Sales YoY and Sales YoY %. Instead I am sending 4 queries and having to calculate Sales CY and Sales PY multiple times and don’t want to do this. I was really hoping visual calcs would solve this issue where it would run the other queries then super quickly do simple thing slike subtracting. Essentially I want to only send queries necessary. Then for YoY or YoY % I want to simply just use the already run queries. I have so many use cases for this. I want to only query a measure once but then use it in multiple columns in different ways. Any thoughts?556Views0likes2CommentsDAX Optimisation
Hi, I have multiple measure that start with the same variable : VAR TO_CALCULATE = IF(AND(COUNTROWS(INDIC) = 1, MAX(INDIC[TYPE_LIGNE]) = "INDIC") , TRUE() , FALSE()) Is it faster to create one separate measure "TO_CALCULATE" with this formula and use this new measure in my multiple other measure ? Thank youSolved439Views0likes1CommentOptimize performance for running totals
Dear all, I am struggling with optimizing the performance of a measure to calculate the running totals. Currently my DAX measure looks like below, but this measure is not performing in the way I would like. I am looking for more effective ways to calculate the running totals, for example using recursive functions. Is there anyone that can help me out with an optimized version to compute the running totals in Power BI? Many measure are depending on this one where we do even more complex analyses, so having this measure optimized will have a profound effect on the overall performance of many dashboards. CALCULATE ( [DemandQty], ALL ( 'Date'[Date] ), 'Date'[Date] <= MAX ( 'Date'[Date] ) )Solved1.4KViews0likes4CommentsHELP!! Add period 0 to calculation without putting it in slicer
Hi everyone, I've been running into a problem for a while now. I am currently working on a financial balance sheet. Currently my dataset consists of the following columns: - Description - Year_Open - Period credit (These are the changes to the opening value) - Period debit (These are the changes to the opening value) - Period (1 to 12 months) As can be seen in the photo above, the opening value is not a period, I wanted to give it the period 0. This made me want to create the formula: Period 0 + selected period in slicer. Does anyone know how I can create this formula in DAX? I also have to ensure that the period 0 is not visible in the slicer, how can I do that? However, I am not very good with DAX formulas and so far I have solved it as shown below. Only then will the total not change if I adjust the slicer, even though this is a requirement. Credit = VAR PeriodCredit = SUM( 'Balance'[Year_Open]) + SUM('Balance'[Period_Debit]) - SUM('Balance'[Period_Credit]) VAR Scoop = NOT(ISINSCOPE(KPI_EOL_xml_GLAccountClassifications[GLClassification2_description])) VAR ScoopPeriodCredit = SUM(Balance[YearClosedCredit]) VAR Result = IF(Scoop,ScoopPeriodCredit,IF(PeriodCredit < 0, - PeriodCredit)) Return Result Hopefully someone can help me with this! Thanks!435Views0likes1CommentOptimized DAX code for calculating on different Filter Context
Hello. I've encountered a Sencario in Which I have to calculate each Value in different FC(Filter Context) based on predefiend Scenarios of A and B. here is my Data Structure in Excel. in above image, [OldCost] and [NewCost] are two Calculated Columns and are the result of [Last Purchase Rate]*[Standard Consuption Rate] and A and B are two Measures calculated by DAX by the following Code snippet for B: = VAR test10 = IF( MAX( BothBOM[ItemCode] ) <> "0501-2020", 0, SUMX( SUMMARIZE( FILTER( ALLEXCEPT( BothBOM, BothBOM[ProductCode] ), BothBOM[ItemCode] = "0501-2020" || BothBOM[ItemCode] = "0501-2014" ), "total", CALCULATE( SUMX( BothBOM, BothBOM[NewCost] ), BothBOM[ItemCode] = "0501-2020" ) - CALCULATE( SUMX( BothBOM, BothBOM[OldCost] ), BothBOM[ItemCode] = "0501-2014" ) ), [total] ) ) VAR test9 = CALCULATE( SUMX( BothBOM, BothBOM[OldCost] ), KEEPFILTERS( LEFT( BothBOM[ItemCode], 4 ) = "0502" ) ) VAR test11 = SUMX( SUMMARIZE( FILTER( ALLEXCEPT( BothBOM, BothBOM[ProductCode] ), BothBOM[ItemCode] = "0501-2020" || BothBOM[ItemCode] = "0501-2014" ), "total2", CALCULATE( SUMX( BothBOM, BothBOM[NewCost] ), BothBOM[ItemCode] = "0501-2020" ) - CALCULATE( SUMX( BothBOM, BothBOM[OldCost] ), BothBOM[ItemCode] = "0501-2014" ) ), [total2] ) RETURN IF( NOT ( HASONEVALUE( BothBOM[ItemCode] ) ), test11 + test9, test9 + test10 ) in summary, in senario B (VAR=test10), I have to calculate for ([ItemCode]="0502-2020") as : ([ItemCode]="0502-2020") minus ([ItemCode]="0501-2014") e.i (433.000-146.000=287.000) and VAR=test11 stands for calculating subtotals in different context. the outcome of these DAX is as expected, but I am wondering if there might be a better solution and better DAX coding?Additionally , I'm curious about the efficeny of this code. specially for VAR=test11 by which I've handeled subtotals for the Measure.525Views0likes1CommentMeasures taking a long time - need help to optimize
Greetings PowerBI community, This is my first post and I have been struggling with this for a while. I will post a lot of screenshots and try to explain the issue. So basically I need help to improve these measures to run faster. I do not understand what is making them so slow. Please help. I basically have two measures that are running a bit slow according the performance analyzer. These measures are [Coverage weighted] and [Coverage numeric] Coverage numeric = DIVIDE(fmInvoiceSales[Active Customer Buy],[Active Customer]) Coverage weighted = DIVIDE(fmInvoiceSales[KFP SM Weighted Sales],fmInvoiceSales[KFP SM Every Sales]) These measures are simple DIVIDE's however its the 4 measures within these DIVIDES that are heavy. One of the DAX Queries that is taking a long time looks like this. It runs particulary slow when using the slicer "Sales Region" which comes from the dmCustomer table. // DAX Query DEFINE VAR __DS0FilterTable = TREATAS({"Horeca Sweden", "North"}, 'dmCustomer'[Sales Region]) VAR __DS0FilterTable2 = TREATAS({"Senaste 52 veckor"}, 'Period Parameter'[Period]) VAR __DS0FilterTable3 = TREATAS({TRUE}, 'dmCustomer'[Active Store CRM]) VAR __DS0Core = SUMMARIZECOLUMNS( 'dmCustomer'[Sales Region], __DS0FilterTable, __DS0FilterTable2, __DS0FilterTable3, "Coverage_weighted", 'fmInvoiceSales'[Coverage weighted], "Coverage_numeric", 'fmInvoiceSales'[Coverage numeric] ) VAR __DS0PrimaryWindowed = TOPN(1001, __DS0Core, [Coverage_weighted], 0, 'dmCustomer'[Sales Region], 1) EVALUATE __DS0PrimaryWindowed ORDER BY [Coverage_weighted] DESC, 'dmCustomer'[Sales Region]886Views0likes1CommentIs there a better way to handle this date control in my measure?
Before I created my memberbase on historical subscriptions per member. That was a small table consisting of 250.000 rows and this measure to show historical development over time worked well: Memberships= Var MaxDate = MAX ( DimDate[Date] ) RETURN CALCULATE( CALCULATE ( COUNT ( FactDonor[#Donornummer] ), FILTER ( FactDonor, ( FactDonor[CreateDate] <= MaxDate && FactDonor[EndDate] > MaxDate ) ), ALL ( DimDate ) ), CROSSFILTER ( FactDonor[CreateDate], DimDate[DateKey], NONE ) ) Now I had to add more change to members, so that I for each row look at membership date as well as changes to other parts such as adress and member-specific things. That means that I have to create lines with change date within the membership dates. It only for added a little over 100.000 rows and my measure now looks like this: Membership = Var MaxDate = MAX ( DimDate[Date] ) RETURN CALCULATE( CALCULATE ( DISTINCTCOUNT ( FactDonor[#Donornummer] ), FILTER ( FactDonor, ( FactDonor[CreateDate] <= MaxDate && FactDonor[EndDate] > MaxDate ) ), FILTER ( FactDonor, ( MaxDate >= FactDonor[ChangeStartingDate] && MaxDate <= FactDonor[ChangeEndingDate] ) ), ALL ( DimDate ) ), CROSSFILTER ( FactDonor[CreateDate], DimDate[DateKey], NONE ) ) My main issue is that the measure is way slower, when creating a chart with memberships per month since january 2021. So is the new measure written correctly or would You handle the change part differently?772Views0likes2CommentsCan this DAX be optimized?
Hi I wonder if this Measure can be optimized a bit? I works as intended, but is a bit slow Seneste betalingsmetode = VAR SenestBetalt = CALCULATE( MAX(FactBetalingslinjer[DatoKeyStoettePeriode]), FactBetalingslinjer[#Payed Amount (GL)] > 0 ) VAR BetaltMetode = CALCULATE( MAX(FactBetalingslinjer[BetalingsmetodeKey]), FactBetalingslinjer[DatoKeyStoettePeriode] = SenestBetalt ) VAR Metode = CALCULATE( MAX(DimBetalingsmetode[BetalingsmetodeNavn]), DimBetalingsmetode[BetalingsmetodeKey] = BetaltMetode ) RETURN Metode I need to find the latest period based on latest payment (Variable SenestBetalt) Then from that date I like to find the payment type (Variable BetaltMetode) Finally I get the paymeny name from the dimension (Variable Metode) The final part is needed (I think) because it's a starschema with all dimensions pointing at FactBetalingslinjer, so I can find the key and then get the name from the dimension. But can it be done smarter? and can it be done faster. Thanks in advance 🙂672Views0likes2CommentsNeed help improving DAX calculations for accurate results in Power BI from single date column!
Hello Power BI community! I'm seeking your expertise to help me improve two DAX calculations that I'm currently using to calculate the receiving and sending (handling) dates for a ticket table. The data I'm dealing with is related to a list of tickets that are received and then treated by technicians on different dates, unfortunately, I'm only provided with one date column which aggregates all actions performed on a specific ticket (which is DateTime), and a ticket may appear repetitively but with different receiving and sending dates (which should be taken into account of course). Here's a snapshot from the raw data table: Feel free to download these tables from here: "https://smallpdf.com/file#s=c745e973-29a0-4dbd-85ab-2472d7379858" Below are the DAX calculations I'm using to produce the results (which are now inaccurate) ReceiverDate = CALCULATE( MIN(WEEKLY_IDs[DateTime]), FILTER( ALL('WEEKLY_IDs'), 'WEEKLY_IDs'[SenderID] = EARLIER('WEEKLY_IDs'[ReceiverID]) && 'WEEKLY_IDs'[ReceiverID] = EARLIER('WEEKLY_IDs'[SenderID]) && 'WEEKLY_IDs'[Ticket_ID] = EARLIER('WEEKLY_IDs'[Ticket_ID]) ) ) SenderDate = CALCULATE( MAX([DateTime]), FILTER( ALL('WEEKLY_IDs'), 'WEEKLY_IDs'[SenderID] = EARLIER('WEEKLY_IDs'[SenderID]) && 'WEEKLY_IDs'[ReceiverID] = EARLIER('WEEKLY_IDs'[ReceiverID]) && 'WEEKLY_IDs'[Ticket_ID] = EARLIER('WEEKLY_IDs'[Ticket_ID]) ) ) These are the end results I'm seeking to accomplish with these two DAX calculations:381Views0likes0CommentsDAX Optimization SUMX ( SUMMARIZE ) - Performance Issue
I'm not able to optimize this measure. I'm new to Power BI DAX. Kindly suggest me a way to run this DAX faster. If I am wrong, please suggest me any other alternative way to achieve the below DAX DAX Measure: Measure name = SUMX ( SUMMARIZE (table_name', table_name'[Col1],table_name'[Col2],table_name'[col3],table_name'[col4],table_name'[col5], "result", CALCULATE ( DISTINCTCOUNTNOBLANK ( table_name'[col1] ), FILTER ( table_name', SUM ( table_name'[Counter] ) = 1 ) ) ), [result] )2.8KViews0likes11Comments