dax
4182 TopicsCreate measure to calculate the difference in values between latest date and previous date
Hi everyone, I need some help. I've already tried different things, including asking LLM, but without any success, so I'm here to ask smarter people for help. I'm trying to create a measure that will give me the difference in a value for a specific entity between the latest date and the previous date. I have 2 tables. The first one contains the date and the entity name and the second one contains the value I want to measure. Both tables are related by a key column and the dates are not daily dates, but ad hoc dates. Something like this: The results I expect to see from the measure should look something like this: And I should be able to put the measure on a card and filter it by the entity name to display the related result. I have tried calculating the latest and previous date and then calculating the corresponding latest and previous value but when I ask to return the difference between latest and previous I never get those expected numbers... My guess is that I'm not using the right formulas to calculates the latest and previous values... Does anybody have an idea? Before anyone asks, I cannot change how the source tables look like as they are automatically generated by a third party software. Thanks in advance.Solved221Views0likes4CommentsDynamic P&L fiscal year time intelligence for actual vs forecast vs budget vs same period last year
Hi Community, I am trying to create a dynamic time intelligent profit and loss statement comparing actuals to forecast, budget, and the same period last year for each line item. I am using a fiscal year calendar which means the standard time intelligence measures will not work. The comparison amount (column) needs to be the variance between the two and not the amount. For example, net sales, the actual amount is 10,000 and the forecast amount is 12,000. The P&L matrix/table should show 10,000 for the actual amount and (2,000) for the forecast amount. Below is a quick picture of what I am trying to achieve: Line-Item Actual vs Forecast vs Budget vs SPLY Net Sales 10,000 (2,000) (1,000) (3,000) COGS 4,000 2,000 1,000 500 Additionally, I would like to see this on a WTD, MTD, QTD, and YTD basis in one matrix/table. Below is a screenshot of the final product I am trying to create along with the format strings: As you can see, we have four different format strings: whole numbers, whole number dollars, decimal, and percentages. My data model is pictured below: Below is a picture of what I currently have: I have created all the individual line-item measures for actuals, forecast, and budget using the measure branching technique. However, I know this is not the best way to do this because I have three measures for each line item. For example, I have a measure for actual net sales, forecast net sales, and budgeted net sales. As you can see, the forecast, budget, and SPLY measures are not variance amounts. The actual, forecast and budget measures use the SWITCH technique which prevents me from calculating the variance because of the four different format strings and a custom time intelligence function. Below is an example of my Actuals measure: Act HL = SWITCH( [Selected Account], 1, FORMAT([Volume], "#,#;(#,#);-"), 2, FORMAT([Net Sales], "$#,#;($#,#);-"), 3, FORMAT([COGS], "$#,#;($#,#);-"), 4, FORMAT([Gross Margin], "$#,#;($#,#);-"), 5, FORMAT([MAP/MDF], "$#,#;($#,#);-"), 6, FORMAT([SG&A], "$#,#;($#,#);-"), 7, FORMAT([Combined EBIT], "$#,#;($#,#);-"), 9, FORMAT([Net Sales Rate], "$#,0.00;($#,0.00);-"), 10, FORMAT([COGS Rate], "$#,0.00;($#,0.00);-"), 11, FORMAT([Gross Margin Rate], "$#,0.00;($#,0.00);-"), 12, FORMAT([MAP/MDF Rate], "$#,0.00;($#,0.00);-"), 13, FORMAT([SG&A Rate], "$#,0.00;($#,0.00);-"), 14, FORMAT([Combined EBIT Rate], "$#,0.00;($#,0.00);-"), 16, FORMAT([GM as % of Net Sales], "0.0%;-0.0%;-"), 17, FORMAT([Combined EBIT as % of Net Sales], "0.0%;-0.0%;-") ) This measure above is then placed into a time intelligence pattern using the SQLBI DAX Patterns for Week-related calculations. As previously mentioned, I am using a fiscal year calendar so the standard time intelligence measures will not work. For example, the Act WTD column in my matrix above is: Act WTD = IF ( [ShowValueForDates], VAR LastDayOfWeekAvailable = MAX ( 'Date'[Day of Week Number] ) VAR LastFiscalYearWeekAvailable = MAX ( 'Date'[Fiscal Year Week Number] ) VAR Result = CALCULATE ( [Act HL], ALLEXCEPT ( 'Date', 'Date'[Working Day], 'Date'[Day of Week] ), 'Date'[Day of Week Number] <= LastDayOfWeekAvailable, 'Date'[Fiscal Year Week Number] = LastFiscalYearWeekAvailable ) RETURN Result ) The matrix has 16 measures like you see above (actual + forecast + budget + SPLY = 4 x 4 = 16 measures) Obviously this not an efficent or sustainable way to create this. I have a feeling Calculation Groups might help solve the problem. Additionally, when slicers are placed on the page, the query is slow because of the number of measures and the size of the data tables. So community, how can I achieve the above? Thank you for taking the time to read through my question.1.8KViews0likes4CommentsCreate new table by transposing/Crosstab a data table
Hi, I need to crosstab/transpose data from one table to create a new table as shown in example below. Original Table: User Week Status A1 Week1 Active A1 Week2 Inactive A1 Week3 Deleted A2 Week1 Active A2 Week2 Active A2 Week3 Deleted A3 Week1 Active A3 Week2 Active A3 Week3 Active A4 Week3 Idle A5 Week2 Active A5 Week3 Active New Table/Changed format/Desired output: User Week1 Week2 Week3 A1 Active Inactive Deleted A2 Active Active Deleted A3 Active Active Active A4 Idle A5 Active Active Can anyone help me with the same? Thanks in advance.Solved2.9KViews1like5CommentsSUMMARIZE, VALUES, and other table generation/manipuation with field parameters
Good day, I have a need to do a correlation coefficient, linear fit, or some other description for the points in a scatter chart, but the Values field bucket uses a field parameter of over 70 possible columns. I would like to use a function like SUMMARIZE, VALUES, or some other kind of table manipulation function to generate a table for my field parameter. For example, if I wanted to generate the correlation coefficient of metrics [metric_x] and [metric_y] by generation, I might do something like this (from quick measures): metric_x and metric_y correlation for generation = VAR __CORRELATION_TABLE = VALUES('DIM_Generation'[Generation]) VAR __COUNT = COUNTX( KEEPFILTERS(__CORRELATION_TABLE), CALCULATE([metric_x] * [metric_y]) ) VAR __SUM_X = SUMX(KEEPFILTERS(__CORRELATION_TABLE), CALCULATE([metric_x])) VAR __SUM_Y = SUMX(KEEPFILTERS(__CORRELATION_TABLE), CALCULATE([metric_y])) VAR __SUM_XY = SUMX( KEEPFILTERS(__CORRELATION_TABLE), CALCULATE([metric_x] * [metric_y] * 1.) ) VAR __SUM_X2 = SUMX( KEEPFILTERS(__CORRELATION_TABLE), CALCULATE([metric_x] ^ 2) ) VAR __SUM_Y2 = SUMX(KEEPFILTERS(__CORRELATION_TABLE), CALCULATE([metric_y] ^ 2)) RETURN DIVIDE( __COUNT * __SUM_XY - __SUM_X * __SUM_Y * 1., SQRT( (__COUNT * __SUM_X2 - __SUM_X ^ 2) * (__COUNT * __SUM_Y2 - __SUM_Y ^ 2) ) ) Is there a way for me to set up __CORRELATION_TABLE to use my field parameter instead of DIM_Generation? I don't want to have to maintain a SWITCH statement for each possible table, which would make maintaining the measures tedious as I may add more fields to my field parameter. Something like this? metric_x and metric_y correlation for field parameter = VAR __CORRELATION_TABLE = VALUES(MAGIC_DAX_FUNCTION('Field_Parameter'[Field Parameter])) VAR __COUNT = COUNTX( KEEPFILTERS(__CORRELATION_TABLE), CALCULATE([metric_x] * [metric_y]) ) VAR __SUM_X = SUMX(KEEPFILTERS(__CORRELATION_TABLE), CALCULATE([metric_x])) ...Solved1.4KViews1like6CommentsDAX Measure for Ranking the valid rows and calculating the average rating
Hi, Appreciate any help. I have two tables – Attendance, Survey I don’t have any joining keys other than email and no way of determining to which survey they responded to if the same MS forms are used for multiple learnings. Attendance Email Course Name Learning Date Status Form Key [email protected] Mathematics - 1 15/03/2026 Completed Form 1 [email protected] Mathematics - 2 20/04/2026 Completed Form 1 [email protected] Mathematics - 3 29/04/2026 Completed Form 2 [email protected] Mathematics - 1 20/04/2026 Registered Form 1 [email protected] Mathematics - 1 20/04/2026 Completed Form 1 [email protected] Mathematics - 3 29/04/2026 Completed Form 2 Survey Email Form Key Survey Date Rating [email protected] Form 1 19/03/2026 5.0 [email protected] Form 1 19/04/2026 2.0 [email protected] Form 1 22/04/2026 3.8 [email protected] Form 2 29/04/2026 2.9 [email protected] Form 1 20/04/2026 4.0 [email protected] Form 1 21/04/2026 3.5 [email protected] Form 2 28/04/2026 2.6 [email protected] Form 2 30/04/2026 4.6 Adam has registered for the learning(20/04/2026) but didn’t attend. But he was able to submit a survey with an automated link that was sent to them. This becomes an invalid submission Eve attended the learning(20/04/2026), submitted a survey before the session(through an automated link – invalid submission) and after the event. Jack attended the learning(20/04/2026) and submitted the survey. Now I need, a rank measure to rank the rows(where valid rows have rank =1). One assumption I can make to rank them is that Learning date <= surveydate<= Learning date + 2 days. a measure which calculates average rating of the valid responses Ex Mathematics – 1, learning date(15/03/2026) = average = blank(no submissions) Mathematics – 1, learning date(20/04/2026) = average = 4.0 Mathematics – 2, learning date(20/04/2026) = average = 3.8 Mathematics – 3, learning date(29/04/2026) = average = (2.9+4.6)/2 = 3.75Solved13KViews1like5CommentsWould you like to know a secret way to delete your DAX UDF code?
🧠 Imagine you've written a brilliant DAX UDF in model view. Finally you decide to add a comment, and suddenly the whole function disappears. 'Undo' is not working. 🚨This happened to me a few days ago. It was my fault for trying to add a comment with "//" above the function header. However, I hadn't expected this to delete the entire function. 💡As I discovered, the problem isn't the comment itself, but characters that aren't allowed in a function name. After(!) deleting the function Power BI displayed a warning : "Special characters are not allowed in a function name..." That put me on the right track. Step-by-step guide to follow: ➡️ Write a DAX UDF in the model view (don't spend to much time on it, as your work will get lost) ➡️ Go to the top of the file ➡️ Press Shift-Enter ➡️ Go back to the top ➡️ Type "// Comment" or any other character that is not allowed in a function name ➡️ Press Enter to save your function ➡️ Is your function still there? ➡️ If not, check wether undoing (Ctrl-Z) works ❓ Is this a bug or a hidden feature? If it is a feature what is it good for? To permanentely delete my work? 🤔 ✒️ I look forward to your comments!556Views6likes2CommentsCalculating filter only for certain rows in a table
I'm having troblues optimizing fitter for a table of 25K rows. It contains companies and their items, there are only 100 companies and a very high number of Items. The filter I want to apply picks top 5 selling companies, but the filter is memory-heavy and the PBI runs out of memory calculating it for 25k rows. My question is, can I calculate it only for the 100 companies, without repeating this for every item? Filter calculation: ShowCompany = VAR N = SELECTEDVALUE('TopNValues'[Ranks]) VAR TopNBrandN = TOPN(N, ALL('unique_brands'[brand]), [SalesForChosenPeriods], DESC ) RETURN IF( CONTAINS( TopNBrandN, unique_brands[brand], SELECTEDVALUE('unique_brands'[brand]) ) || N = 0, 1, 0 )Solved696Views1like4CommentsApply Conditional Formatting to a Column and am seeking assistance
Hello All, I would like to apply conditional formatting to a column and am seeking assistance. My goal is to enable users to select a color that will automatically be applied to a column header in Power BI, based on data sourced from Excel. For instance, if a user selects '1', the color should be green; for '2', blue; and for '3', red. Please be aware that the report is updated monthly. Therefore, as users change values in Excel each month, these changes should be dynamically reflected in Power BI. I'm facing a challenge with applying conditional formatting to a column instead of a row. If you have a more effective way to model the data, your suggestions would be greatly appreciated. My brain is a bit fatigued, just want to see column conditional formatted.😁 Can anyone provide a solution for this? I have included a screenshot below for better clarity.Solved5.1KViews0likes4CommentsCurrency FX Rates
Hi everyone, I have a pretty challenging DAX task (In my opinion, hopefully someone tells me it's easy!). I am currently putting together a balance sheet and I have the following CurrencyFX table: company starting_date month rate type number Company_1 01/04/2026 Apr-26 0.01401 Monthly 0 Company_1 01/03/2026 Mar-26 0.014146 Monthly 0 Company_1 28/02/2026 Feb-26 0.014184 Monthly 0 Company_1 31/01/2026 Jan-26 0.014286 Monthly 0 Company_2 01/04/2026 Apr-26 0.864304 Monthly 0 Company_2 01/03/2026 Mar-26 0.871916 Monthly 0 Company_2 28/02/2026 Feb-26 0.878272 Monthly 0 Company_2 31/01/2026 Jan-26 0.867002 Monthly 0 Company_3 01/04/2026 Apr-26 0.008072 Monthly 0 Company_3 01/03/2026 Mar-26 0.008126 Monthly 0 Company_3 28/02/2026 Feb-26 0.008169 Monthly 0 Company_3 31/01/2026 Jan-26 0.00793 Monthly 0 Company_4 01/04/2026 Apr-26 0.864304 Monthly 0 Company_4 01/03/2026 Mar-26 0.871916 Monthly 0 Company_4 28/02/2026 Feb-26 0.878272 Monthly 0 Company_4 31/01/2026 Jan-26 0.882768 Monthly 0 Company_2 01/01/2026 Jan-26 0.903222 Account 20101 Company_4 01/01/2026 Jan-26 0.837333 Account 20101 Company_3 01/01/2026 Jan-26 0.008748 Account 20101 Company_1 01/01/2026 Jan-26 0.014078 Account 20101 Company_2 01/01/2026 Jan-26 0.903222 Account 20102 Company_4 01/01/2026 Jan-26 0.837333 Account 20102 Company_3 01/01/2026 Jan-26 0.008748 Account 20102 Company_1 01/01/2026 Jan-26 0.014078 Account 20102 Company_2 01/01/2026 Jan-26 0.903222 Account 20103 Company_4 01/01/2026 Jan-26 0.837333 Account 20103 Company_3 01/01/2026 Jan-26 0.008748 Account 20103 Company_1 01/01/2026 Jan-26 0.014078 Account 20103 Company_2 01/01/2026 Jan-26 0.903222 Account 20201 Company_4 01/01/2026 Jan-26 0.837333 Account 20201 Company_3 01/01/2026 Jan-26 0.008748 Account 20201 Company_1 01/01/2026 Jan-26 0.014078 Account 20201 Company_2 01/01/2026 Jan-26 0.903222 Account 20202 Company_4 01/01/2026 Jan-26 0.837333 Account 20202 Company_3 01/01/2026 Jan-26 0.008748 Account 20202 Company_1 01/01/2026 Jan-26 0.014078 Account 20202 Company_2 01/01/2026 Jan-26 0.830597 Account 20301 Company_4 01/01/2026 Jan-26 0.872245 Account 20301 Company_3 01/01/2026 Jan-26 0.008247 Account 20301 Company_1 01/01/2026 Jan-26 0.014376 Account 20301 Company_2 01/01/2026 Jan-26 0.830597 Account 20302 Company_4 01/01/2026 Jan-26 0.872245 Account 20302 Company_3 01/01/2026 Jan-26 0.008247 Account 20302 Company_1 01/01/2026 Jan-26 0.014376 Account 20302 Company_2 01/01/2026 Jan-26 0.830597 Account 20303 Company_4 01/01/2026 Jan-26 0.872245 Account 20303 Company_3 01/01/2026 Jan-26 0.008247 Account 20303 Company_1 01/01/2026 Jan-26 0.014376 Account 20303 Company_5 01/01/2026 Jan-26 1 Fixed 0 Company_6 01/01/2026 Jan-26 1 Fixed 0 Company_7 01/01/2026 Jan-26 1 Fixed 0 Company_8 01/01/2026 Jan-26 1 Fixed 0 Company_9 01/01/2026 Jan-26 1 Fixed 0 Company_10 01/01/2026 Jan-26 1 Fixed 0 Company_11 01/01/2026 Jan-26 1 Fixed 0 Company_12 01/01/2026 Jan-26 1 Fixed 0 My Base measures are: Actual = SUM(GLEntry[Amount]) Actual Cumulative = VAR CurrentMonth = MAX('DimDate'[Date]) RETURN CALCULATE( [Actual], FILTER( ALL('DimDate'), 'DimDate'[Date] <= CurrentMonth ) ) I have the following requirements: If CurrencyFX[Type] = "Monthly", multiply Actual by the current months rate for that company. This is a balance sheet so I will be using a cumulative figure. In January multiply Januarys Actual by January rate. In February, multiply January + February Actual by Februarys rate, etc. If CurrencyFX[Type] = "Account", when GLEntry[GLAccountNo] = CurrencyFX[number] for the specified company, multiply Actual by that rate in every month. If CurrencyFX[Type] = "Fixed" always multiply by that rate (Intention is to give Actual without conversion) I have the following DAX measures that work only when a company is selected. I need to be able to select all companies to provide group numbers. I added all companys to the fx table and added a relationship to DimCompany to see if this would fix it but it didn't. FX Account = CALCULATE( MAX(CurrencyFX[rate]), TREATAS( VALUES(GLEntry[GLAccountNo-3]), CurrencyFX[number] ), TREATAS( VALUES(GLEntry[$Company]), CurrencyFX[company] ) ) FX Monthly = CALCULATE( MAX(CurrencyFX[rate]), TREATAS( VALUES(GLEntry[$Company]), CurrencyFX[company] ), TREATAS( VALUES(DimDate[MonthYear]), CurrencyFX[month] ) ) FX Fixed = CALCULATE( MAX(CurrencyFX[rate]), TREATAS( VALUES(GLEntry[$Company]), CurrencyFX[company] ), CurrencyFX[type] = "Fixed" ) FX Rate = COALESCE( [FX Account], [FX Monthly], [FX Fixed] ) Actual FX = [Actual] * [FX Rate] Actual Cumulative = VAR CurrentMonth = MAX('DimDate'[Date]) RETURN CALCULATE( [Actual FX], FILTER( ALL('DimDate'), 'DimDate'[Date] <= CurrentMonth ) ) I hope I have explained that well enough! Looking forward to your inputs. I can't post GLEntry data for obvious reasons. Thanks!Solved826Views2likes5CommentsPrevious Year Measure for Line Chart
Hello. I am trying to create a YOY cumulative active customer by month line chart. The line should show the number of customers who made at least one purchase. One for Selected Year and another for Selected Year - 1. And, the total is rolling, so the line should be going up over time. Because there is a year filter in play, I am having difficulties writing a measure that provides a PY Active Customer line for the line chart. If I have 2026 selected, previous years' active customers is reduced. So, I have to removefilter the Calendar. However, this causes the PY active customer line ignore the month on the X axis resulting in a flat total line. Please help me write a measure that accurately calculates PY active customers and still works in a line chart. Should look something like this: Sample file here. Thanks.Solved3.4KViews0likes10Comments