virtual table
30 Topicsusing Virtual tables to get running total
Hi, Would like to use virtual table to have a running sum on measure delta like matrix below. Delta works fine. is based on measure 1 and 2. Measure 2 is special: data depends on calendar!YearMonth: data previous month (202504) is something else compared to current month and later YearMonth are also columns in matrix. Should be 202504 202505 202506 202507 202508 202509 202510 202511 202512 measure1 100 100 100 100 100 100 100 100 100 measure2 50 60 60 60 60 60 60 60 60 measure delta 50 40 40 40 40 40 40 40 40 running total 50 90 130 170 210 250 290 330 370 But is 202504 202505 202506 202507 202508 202509 202510 202511 202512 measure1 100 100 100 100 100 100 100 100 100 measure2 50 60 60 60 60 60 60 60 60 measure delta 50 40 40 40 40 40 40 40 40 running total 50 150 250 350 450 550 650 750 850 Code below shows me correct running total but I can not use it as a measure. It always shows me delta instead of running total. How can I use 'running total' in my measure ? And also, if any selections in PROD and GEO dimension tables, will these be reflected in this measure, using virtual tables ? Or should I capture selection in the measure ? TableRunningTotal = VAR curM = VALUE(CONCATENATE(YEAR(now()), FORMAT(MONTH(now()),"00")) ) VAR prevM = IF(MONTH(today())=1, VALUE(CONCATENATE(YEAR(today())-1, "12")), VALUE(CONCATENATE(YEAR(today()), FORMAT(MONTH(TODAY())-1,"00"))) ) VAR T1 = SUMMARIZE( FILTER(ALL(DATA),VALUE([Month]) >= prevM), 'Calendar'[YearMonth], "measure1", CALCULATE(sum(DATA[Value]), DATA[Measure] = "1"), "measure_X", CALCULATE(sum(DATA[Value]), DATA[Measure] = "X"), "measure_Y", CALCULATE(sum(DATA[Value]), DATA[Measure] = "Y"), ) VAR T2 = ADDCOLUMNS(T1, "measure2", if(VALUE([YearMonth]) < curM, [measure_X], [measure_Y]) ) VAR T3 = ADDCOLUMNS(T2, "Delta", [measure1]-[ measure2] ) VAR T4 = ADDCOLUMNS(T3,"RunningTotal", SUMX(FILTER(T3, [YearMonth]<=EARLIER([YearMonth])), [Delta]) ) RETURN --T4 : shows in table view (create table) ==> correct running total --SUMX(T4,[RunningTotal]) : shows only delta’s per YearMonth --MAXX(T4,[RunningTotal]) : shows only delta’s per YearMonth --SELECTCOLUMNS(T4," ", [RunningTotal]) : shows only delta’s per YearMonthSolved2.3KViews0likes13CommentsHelp with Running Sum Measure Using Virtual Tables and Rank in DAX
Hi everyone, I'm trying to create a running sum measure in DAX that changes dynamically based on the applied filters. The running sum should accumulate values according to the rank of each row. I've already created separate tables, and they work as expected. However, when I attempt to implement this using a measure with virtual tables, it doesn't produce the desired result. Here's the code I'm working with. Each part seems to work independently (e.g., ranking and filtering), but as a combined measure, it fails to return the correct running sum per rank. Running_sum_measure = VAR tbl_1 = ADDCOLUMNS( FILTER(ALL(sales_table[CodigoArticulo]),[CQ1]>0) ,"porc" ,[PorcentajeParticipacionCQ1] ) VAR tbl_1_sorted = ADDCOLUMNS( tbl_1, "Rank", RANKX( tbl_1, [porc] + RAND() * 0.0001, // Adding a slightly larger random component to ensure uniqueness , DESC, Dense ) ) VAR table_rank = ADDCOLUMNS( tbl_1_sorted, // Columna "RowNumber" para asignar un número de fila único a cada registro "RowNumber", RANKX( ALL(tbl_1_sorted), // Considera todos los registros de la tabla sin filtros [Rank] + RANKX( ALL(tbl_1_sorted), CALCULATE( MAXX(tbl_1_sorted, tbl_1_sorted[CodigoArticulo]) // Valor máximo de CodigoArticulo para el desempate ), , ASC, Dense // Usa Dense para clasificaciones consecutivas ) / COUNTROWS(ALL(tbl_1_sorted)), // Ajuste para evitar empates basado en el total de filas , ASC, Dense // Usa clasificación ascendente y consecutiva para "RowNumber" ) ) VAR final_ = ADDCOLUMNS( SUMMARIZE( table_rank, table_rank[CodigoArticulo], table_rank[RowNumber], "porc", SUM(table_rank[porc]) ), "RunningSum", VAR CurrentRank = [RowNumber] RETURN CALCULATE( SUM(table_rank[porc]), FILTER( ALL(table_rank), table_rank[RowNumber] <= CurrentRank && table_rank[CodigoArticulo] = [CodigoArticulo] ) ) ) VAR running_current = SUMX(final_,[RunningSum]) RETURN running_current the initital table will look something like this CodigoArticulo porc abc234hj21 0.001269819292983 bc234hj21 0.023401928347459 bc234hj223 0.032123394040404 bc234hj24gn 0.011001110932900 If anyone has experience with handling ranks with tie-breakers in a measure like this, I’d appreciate any advice on how to make this running sum work dynamically with filters and rankings. Thank you in advance for any help you can provide!Solved1KViews1like1CommentDebug DAX measure variables incl. virtual tables
Hi, I created an idea to be able to visually inspect the variables of a DAX measure, when the DAX measure is used in a table visual, line chart visual, etc. Please vote 😀 https://ideas.fabric.microsoft.com/ideas/idea/?ideaid=a7a31361-2f40-ef11-b4ac-6045bdbf86b41.2KViews0likes2Commentsapply slicer values in virtual table
Hi, I would like to have a measure obtaining a virtual table where all my slicers (15) selections or non-selections are applied to. With this filtered table, I still have to perform several actions to get my final measure. Using SUMMARIZE should keep all filters, is what I've read. There is 1 fact table (v_BI_DATA_AG), 1 calendar table (Calendar) and 2 dimension tables (v_Product_AG and vGeoAG). All relations are set. Below does not work. Result is not filtered automatically according to all 15 slicer selections. it's not filtered at all. How should I solve this ? Another way ? Side question: SELECTEDVALUE only returns when 1 option in slicer is selected. How handle no selection ? And multiple selections ? VAR SelectedMonth = SELECTEDVALUE('Calendar'[YearMonth]) VAR SelectedQuarter = SELECTEDVALUE('Calendar'[Quarter]) VAR SelectedYear = SELECTEDVALUE('Calendar'[Year]) //defining month/Q/Y VAR curMonth = IF(NOT ISBLANK(SelectedMonth) , SelectedMonth, IF(NOT ISBLANK(SelectedQuarter), LEFT(SelectedQuarter,4) & IF(LEN(3* RIGHT(SelectedQuarter,1))<2,"0" & 3* RIGHT(SelectedQuarter,1),3* RIGHT(SelectedQuarter,1)), SelectedYear & 12 ) ) VAR Curinventory = CALCULATE(SUM(v_BI_DATA_AG[Value]), v_BI_DATA_AG[TYPE]="IN", 'v_BI_DATA_AG'[Month] = CONVERT(curMonth,INTEGER) ) VAR LoopTable = SUMMARIZE( 'v_BI_DATA_AG' , 'Calendar'[YearMonth], v_BI_DATA_AG[cycle], v_Product_AG[Business], v_BI_DATA_AG[NF], vGeoAG[Region], vGeoAG[Sub Region], vGeoAG[Area], vGeoAG[Market], v_Product_AG[Plant], v_Product_AG[Model], v_Product_AG[PL], v_Product_AG[Brand], v_Product_AG[Family], "SalesMonth", CALCULATE(sum(v_BI_DATA_AG[Value]), v_BI_DATA_AG[TYPE] = "SALES"), "I", CALCULATE(sum(v_BI_DATA_AG[Value]), v_BI_DATA_AG[TYPE] = "IN") )Solved861Views0likes2CommentsCalculate accumulated product sales ending expiry dates using Dax
I was trying to calculate accumulated sales ending expiry dates. The target is to calculate the accumulated sales till the month the product expires. I used a measure to calculate it. However it didn't work. Can any expert advise how the measure can be adjusted or re-developed to suit this scenario? Thanks very much! The link to the PBI report is below: Accumulated sales PBI report I have a list of products with the following expiry dates: Product Code Expiry Month A 202205 B 202206 C 202207 The sales by month for them are as follows: Calendar month Product Code Amount 202204 A 1000 202205 A 1000 202206 A 1000 202207 A 1000 202208 A 1000 202204 B 1000 202205 B 1000 202206 B 1000 202207 B 1000 202208 B 1000 202204 C 1000 202205 C 1000 202206 C 1000 202207 C 1000 202208 C 1000 The desired output of accumulated sales is as follows: Calendar Month A B C Total 202204 1000 1000 1000 3000 202205 2000 2000 2000 6000 202206 3000 3000 6000 202207 4000 40001.4KViews0likes5CommentsCreate a virtual table in Dax to calculate account balance for products with different expiry dates
I have product A, B, C. They each have opening balance amount at 1/11/2023 ,say 3000, 7000 and 11000 for A,B,C respectively. They each have expiry dates, say A, B and C expires on 11/11/2023, 5/11/2023 and 30/11/2023 respectively. The opening balance needs to be calculated each month until the expiry dates for the product, i.e. from 1/11 to 5/11, the total opening balance will be 21000 (for all the 3 products) and from 6/11 to 11/11, the total opening balance will be 14000 (3000+11000 for A and C as B has expired) and from 12 to 30/11, the total opening balance will be 11000 (for C only) as both A and B have expired. Is there a way to create a single measure through creation of virtual table or others to achieve this outcome. I tried the following codes but it didn't work: Calculated opening balance test= var latestdate=min(Dim_Date[Date ID]) var latestexpirydate=min(Dim_Expiry_Date[Expiry Date]) var datetable=filter(CROSSJOIN(all(Dim_Date),Dim_Expiry_Date),latestdate<=latestexpirydate) return sumx(datetable,sum(Fact_Account_Opening_Balance[Amount])) Please find below the link to the sample PBI report. Appreciate some experts can help with the dax!! Thank you in advance! Product account balance PBI report Opening balance Date ID Account Code Product Code Amount 1/11/2023 1001 A 1000 1/11/2023 1002 A 2000 1/11/2023 1001 B 3000 1/11/2023 1002 B 4000 1/11/2023 1001 C 5000 1/11/2023 1002 C 6000 Expiry date Product Code Expiry Date A 11/11/2023 B 5/11/2023 C 30/11/2023 Desired output Date ID A B C Total 1/11/2023 3000 7000 11000 21000 2/11/2023 3000 7000 11000 21000 3/11/2023 3000 7000 11000 21000 4/11/2023 3000 7000 11000 21000 5/11/2023 3000 7000 11000 21000 6/11/2023 3000 0 11000 14000 7/11/2023 3000 0 11000 14000 8/11/2023 3000 0 11000 14000 9/11/2023 3000 0 11000 14000 10/11/2023 3000 0 11000 14000 11/11/2023 3000 0 11000 14000 12/11/2023 0 0 11000 11000 13/11/2023 0 0 11000 11000 14/11/2023 0 0 11000 11000 15/11/2023 0 0 11000 11000 16/11/2023 0 0 11000 11000 17/11/2023 0 0 11000 11000 18/11/2023 0 0 11000 11000 19/11/2023 0 0 11000 11000 20/11/2023 0 0 11000 11000 21/11/2023 0 0 11000 11000 22/11/2023 0 0 11000 11000 23/11/2023 0 0 11000 11000 24/11/2023 0 0 11000 11000 25/11/2023 0 0 11000 11000 26/11/2023 0 0 11000 11000 27/11/2023 0 0 11000 11000 28/11/2023 0 0 11000 11000 29/11/2023 0 0 11000 11000 30/11/2023 0 0 11000 11000Solved1.3KViews0likes3CommentsRemove Table Filters While Using Virtual Table Measures
Hello! I'm currently trying to return the max value from a virtual table that I will use in another virtual table, along with removing the table filters when I place this max value in a table visual. Specifically, the 'MAX Efficiency Score' measure will be utilized in the 'Efficiency Score' measure (see 'var table7' in the 'Efficiency Score' measure). Efficiency Score = var table1 = SUMMARIZE('Fuel (Traveling)', 'Fuel (Traveling)'[Driver Fleet Name], 'Fuel (Traveling)'[DriverName/ID], "EffScore", -[True Avg. Travel Difference]) var table2 = ADDCOLUMNS(table1, "DriverCountFleet", CALCULATE(DISTINCTCOUNT('Fuel (Traveling)'[DriverID]), ALLEXCEPT('Fuel (Traveling)', 'Fuel (Traveling)'[Driver Fleet Name], 'Combined Calendar'[Date - Copy])), "OrderCountFleet", CALCULATE(DISTINCTCOUNT('Fuel (Traveling)'[Order ID]), ALLEXCEPT('Fuel (Traveling)', 'Fuel (Traveling)'[Driver Fleet Name], 'Combined Calendar'[Date - Copy])), "OrderCountDriver", CALCULATE(DISTINCTCOUNT('Fuel (Traveling)'[Order ID])) + 0) var table4 = ADDCOLUMNS(table2, "AvgOrders", DIVIDE([OrderCountFleet], [DriverCountFleet])) var table5 = ADDCOLUMNS(table4, "Ratio", DIVIDE([OrderCountDriver], [AvgOrders])) var table6 = ADDCOLUMNS(table5, "Score", IF([Ratio] > 1, [EffScore] * 1, [EffScore] * [Ratio])) var table7 = ADDCOLUMNS(table6, "FinalScore", [Score]/[MAX Efficiency Score]) var table8 = SUMX(table7, [Score]) return table8 MAX Efficiency Score = var table1 = SUMMARIZE('Fuel (Traveling)', 'Fuel (Traveling)'[Driver Fleet Name], 'Fuel (Traveling)'[DriverName/ID], "EffScore", -[True Avg. Travel Difference]) var table2 = ADDCOLUMNS(table1, "DriverCountFleet", CALCULATE(DISTINCTCOUNT('Fuel (Traveling)'[DriverID]), ALLEXCEPT('Fuel (Traveling)', 'Fuel (Traveling)'[Driver Fleet Name], 'Combined Calendar'[Date - Copy])), "OrderCountFleet", CALCULATE(DISTINCTCOUNT('Fuel (Traveling)'[Order ID]), ALLEXCEPT('Fuel (Traveling)', 'Fuel (Traveling)'[Driver Fleet Name], 'Combined Calendar'[Date - Copy])), "OrderCountDriver", CALCULATE(DISTINCTCOUNT('Fuel (Traveling)'[Order ID])) + 0) var table4 = ADDCOLUMNS(table2, "AvgOrders", DIVIDE([OrderCountFleet], [DriverCountFleet])) var table5 = ADDCOLUMNS(table4, "Ratio", DIVIDE([OrderCountDriver], [AvgOrders])) var table6 = ADDCOLUMNS(table5, "Score", IF([Ratio] > 1, [EffScore] * 1, [EffScore] * [Ratio])) var final = ADDCOLUMNS(table6, "MaxValue", MAXX(table6, [Score])) return CALCULATE(MAXX(final, [MaxValue]), ALL('Fuel (Traveling)')) My current issue is that I can't get the 'MAX Efficiency Score' measure to return the max score of 79.58 (in the case below) for each row of my table visual below. For background, the table visual below contains the same fields (Driver Fleet Name and DriverName/ID) that are used in the SUMMARIZE functions above. I also set the dashboard up so the 'Efficiency Score' and 'MAX Efficiency Score' values dynamically update when the date slider is used, which is why I referenced the 'Combined Calendar[Date - Copy] field in the measures above. I'd really appreciate any help I could get on this issue. Thanks!729Views0likes3CommentsLookup between virtual tables without relationship
Hi guys, I am quite new to DAX magic and been practicing a lot in the last few months, but still I can't fully understand the concept of lookup values based on columns from "virtual tables", even though I've read the articles about it, and also about the TREATAS function that probably should help here. No matter which method i've used in my code to add the column of lookup value from one table to another, I'm getting the same message of "table variable "xxx" cannot be used in this concept, because a base table is expected" 😕 Anyway, my example is very simple: DEFINE VAR _size = ADDCOLUMNS ( SUMMARIZECOLUMNS ( 'person'[person id] ), "total", 'measures'[total] ) VAR _tbl = ADDCOLUMNS ( SUMMARIZECOLUMNS ( 'person'[person id], 'mgr'[mgr id] ), "lookup", LOOKUPVALUE ( '_size'[total], '_size'[person id], '_tbl'[mgr id], 0 ) ) EVALUATE _tbl definitions: 'person' and 'mgr' are actual physical tables, [total] is a meassure as part of the model. so the idea is to add a new column to _tbl1 called "lookup" that will bring the [total] for each [mgr id] matching [mgr id] to [person id]. so as mentioned the error i get is about the fact that those tables are not physical ones in my model, but a virtual temp tables that i'm creating in thie query. so what's the method that can be used to do a lookup between non-related virtual table variables? thanks!1.1KViews0likes2Commentsdynamic conditional formatting with virtual table and switch
Hi, im having an issue building dynamic conditional formatting on my visual (color columns) The reason why i need to build that are all spaces in between columns in a chart, if more trafo numbers are selected than the spaces gets bigger To do that i added a table with ColorID and HEX rgb. I want to build virtual table with all selected Serial Numbers from slicer, adding HEX rgb by matchin the ID from virtual table and colorID and then with switch return HEX rgb. The problem i have is that it always return same hex rgb with index nr 1 IndexColorTrafo = var CurrentSelection=MAX(MeasurementsByFrequency[Serial Number]) VAR SelectedTrafoIDs = VALUES(MeasurementsByFrequency[Serial Number]) VAR NumSelectedTrafoIDs = COUNTROWS(SelectedTrafoIDs) VAR VirtualTable = ADDCOLUMNS( GENERATESERIES(1, NumSelectedTrafoIDs), "TrafoID", SELECTEDVALUE(MeasurementsByFrequency[Serial Number]), "ColorID", LOOKUPVALUE(TblCSSColor[Hex rgb],TblCSSColor[ColorID],[Value]) ) RETURN VAR Output= MAXX( VirtualTable, //VAR CurrentTrafoID = [TrafoID] //RETURN IF( NumSelectedTrafoIDs = 0, BLANK(), SWITCH( TRUE(), //[TrafoID]=CurrentSelection, CONTAINSSTRING(SelectedTrafoIDs, CurrentSelection), [ColorID], BLANK() ) ) ) Return Output anyone can help?