need help (using direct query)
15 TopicsDAX Running total in Direct Query, but reset to zero each day, if running below zero
Hi Power BI Community, I have an issue, where I want to calculate a running total in a measure, so I'm able to get the primo and ultimo value of the stock quantity. This is a forecast of the stcok 14 days ahead of time, and to be sure that we won't run below zero on a given day. In the event of the running total going below zero, I need it to reset and use the 0 as the new starting point. Backstory I need to use Direct Query as the data source connection. I have therefore limitations that I cannot use a calculated column, since I cannot use CALCULATE in calculated columns due to Direct Query. I have no possibility to throw the calculation out of DAX and Measures and into Power Query, again due to Direct Query limitations. I don't have a possibility to put the calculation outside of DAX, so I need to find a solution within measures, that I can use. Where I'm at right now My data looks a bit like this: Item Date Primo Sales Purchase Ultimo 1 16-08-2024 1.429 771 0 658 1 17-08-2024 658 1136 0 -1136 1 18-08-2024 0 4 384 380 1 19-08-2024 380 594 0 -594 1 20-08-2024 0 630 0 -630 1 21-08-2024 0 659 0 -659 1 22-08-2024 0 821 0 -821 1 23-08-2024 0 167 0 -167 1 24-08-2024 0 4 0 -4 1 25-08-2024 0 3 0 -3 1 26-08-2024 0 0 0 0 1 27-08-2024 0 0 0 0 1 28-08-2024 0 0 0 0 1 29-08-2024 0 0 0 0 I have tried to put everything into my ultimo calculation, but I can also see that that is the source of the error. I have 3 measures that's just a sum of the data in the table: WarehouseflowSales = SUM(warehouseflow[sales]) WarehouseflowPurchase = SUM(warehouseflow[purchase]) WarehouseflowInventory = SUM(warehouseflow[inventory]) Then I have the measure for the Ultimo column: WarehouseflowUltimo = VAR MaxDate = MAX(warehouseflow[date]) VAR UltimoYesterday = CALCULATE( -[WarehouseflowSales] + [WarehouseflowPurchase], ALLEXCEPT(warehouseflow, warehouseflow[itemno]), warehouseflow[date] < MaxDate ) + [WarehouseflowInventory] RETURN IF( UltimoYesterday < 0, 0, UltimoYesterday + [WarehouseflowPurchase] - [WarehouseflowSales] ) The measure for the Primo column is just the ultimo value from the day before: WarehouseflowPrimo = VAR MaxDate = MAX(warehouseflow[date]) VAR UltimoYesterday = CALCULATE( [WarehouseflowUltimo], ALLEXCEPT(warehouseflow, warehouseflow[itemno]), warehouseflow[date] = MaxDate - 1 ) RETURN IF( MaxDate = TODAY(), [LagerflowInventory], IF( UltimoYesterday < 0, 0, UltimoYesterday ) ) I have tried to edit the measure to use a somewhat circular reference, but whereas I handle the calculation for the WarehouseflowUltimo measure by date. Meaning that if the the date is today, then I should add the WarehouseflowPurchase and subtract the WarehouseflowSales to the WarehouseflowInventory. If it is not today, then I should use the WarehouseflowPrimo instead of the WarehouseflowInventory. Do you have any suggestions as to how I can handle this? Possible solution I can see myself I have thought of a solution to create 14 different measures, since I need to handle 14 days within my forecast. Then I should be able to handle the issue day by day. I'm just a bit tied on hands and legs due to performance on this issue as well. I haven't tried it yet, but would like to hear your suggestions first 😊Solved1.9KViews0likes5CommentsGet the average of a column value based on total count of values in ID column
Hi, In a table i have column called "Object" which runs multiple times in a day and that runtime is captured in "StartTime" & "EndTime" columns, and the difference between the start and end time is captured in the "Duration" Column. Each object will be having multiple runid's which is captured in "RunID" column which is a unique value. For eg: Object AAA has two runid's called "111,222" and Object BBB has one runid called "333". Now i would like to get the average of each duration by count of that particular runid which is captured in "New Duration" column. For eg: The count of 111 runid is '10'. so for all those durations with runid 111 should be divided by the 10. The count of 222 runid is '6'. so for all those durations with runid 222 should be divided by the 6. The count of 333 runid is '8'. so for all those durations with runid 333 should be divided by the 8. Sample screenshot for above query: So since my Duration is "10" and total count of runid (111) is 10. So 10/10=1 that is my newduration.Similarly for all durations with runid's 111 should be divided bt 10. How to achieve this using DAX query?? I am connecting to this table in powerbi via SQL direct query mode. Thanks.Solved1.1KViews0likes2CommentsLast N months from selected month
Hi Team, Please do needful for the following criteria. I have the below kind of data, the requirement i need is , if we select May, we need to show last four months data(Feb, Mar, apr, May) . and it should be based on year also(Ex:- if we select 2022 feb, then result is 2021 Nov, 2021 dec, 2022 jan, 2022 feb) Thanks in Advance.Solved6KViews0likes4CommentsDAX to compare two columns and set color for the KPI column
Hi All, I have an employee table with Salary ,employee and benchmark columns . I need to compare the benchmark column with Salary column and if Salary > benchmark then KPI color column should be Green, If Salary < benchmark then KPI color column should be Red and if Salary = benchmark then KPI color column should be Yellow. Could you please suggest any DAX to handle this ? I need to show the KPI color column as shown below in expected output screenshot. My Source input Table is as below :- Salary Benchmark KPIColor Employee 20000 15000 Green color should be filled E1 10000 15000 Red color should be filled E2 15000 15000 Yellow color should be filled E3 Expected output :- Kind regards SameerSolved622Views0likes1CommentCircular dependency error: DAX calculation to find sum of column values for Present & Previous Month
Hi All, I have a table say website, I want to form a DAX which can provide me the sum of the Ranking for the month July and June. August is the current month as of now. so i need the sum for last month(July) and previous of last month(June) The DAX calculation should get the SUM of Ranking = 12 for July and SUM of Ranking = 4 for June I tried using the below DAX query but it is throwing circular error . Can someone please suggest what modifications can i make to calculate the sum of Ranking for June month? For July the DAX calculation works fine :- last_month_click = CALCULATE ( SUM ( 'Website'[Clicks] ), MONTH ( 'Website'[date] ) = MONTH ( TODAY () ) - 1 ) For June the DAX throws circular dependency error for below formula:- Previousof_last_month_click = CALCULATE ( SUM ( 'Website'[Clicks] ), MONTH ( 'Website'[date] ) = MONTH ( TODAY () ) - 2 ) My data source input is as below :- Ranking Clicks date 1 2000 02.08.2021 2 1200 01.08.2021 1 2300 01.08.2021 3 1000 31.07.2021 4 900 29.07.2021 -1 200 28.07.2021 -2 100 27.07.2021 1 2400 26.07.2021 2 2100 25.07.2021 4 1300 24.07.2021 1 1800 21.07.2021 1 1400 29.06.2021 2 1100 27.06.2021 1 1300 25.06.2021 Please suggest. Kind regards SameerSolved1.8KViews0likes6CommentsDAX Query to find Sum of column values per month
Hi All, I have a table say " Website" and have three columns as below "Ranking","Clicks" and "date" :- I need to find the sum of the Clicks and Ranking column for present month "August" and previous month "July". It should happen for all upcoming months Ranking Clicks date 1 2000 02.08.2021 2 1200 01.08.2021 1 2300 01.08.2021 3 1000 31.07.2021 4 900 29.07.2021 -1 200 28.07.2021 -2 100 27.07.2021 1 2400 26.07.2021 2 2100 25.07.2021 4 1300 24.07.2021 1 1800 21.07.2021 Expected values are in yellow : I want DAX query to return the sum of the Ranking and Clicks for Current month and previous month after extracting month value from date column. I tried to use the below DAX for finding sum of click and reputation, but I got this error :- current_month_click = CALCULATE(SUM('Website'[Click]),FILTER('Website',MONTH('Website'[Month])=MONTH(TODAY()))) last_month_click= var current_month= MONTH(TODAY()) return CALCULATE(SUM('Website'[Click]),FILTER('Website',MONTH('Website'[Month])=current_month -1)) But it is not working, can someone suggest any modification or any DAX to handle this . Kind regards Sameer790Views0likes4CommentsDAX to compare with system date and find attendance dates for today
Hi All, I have a table named school as shown below . Here Attendance dates columns are populated on a daily basis.It can also contain old records sometimes but we need to mark them as NA and red color in the cell of the tabular matrix in powerBI As per my requirement if the attendance date is not equal to the systemdate then it should show NA and mark the cell as red dynamically. Say today is "15.07.2021" then the third row has entry "14.07.2021 10.09.21" this cell needs to be filled with red color with text NA replacing "14.07.2021 10.09.21". Could anyone please suggest any DAX to handle this situation? Attendance Date swipeLocation StudentID Name 15.07.2021 11:05AM Gate1 101 Tom 15.07.2021 10.03.22 Gate1 102 Hary 14.07.2021 10.09.21 Gate2 103 Rohan 15.07.2021 09.03.18 Gate2 105 Mohan 15.07.2021 10.08.22 Gate2 109 Sam 15.07.2021 10.03.12 Gate2 110 Sally Kind regards SameerSolved854Views0likes3CommentsDAX to find KPI of ratings per month
Hi Anonymous Hi All, I have a table company as below . Ratings column shows the company ratings from -5 to 5 range. The current month now is July and it is not completed so whatever is the current system date say 16-jul-2021(system date today) we need to take range till 16-Jun2021 for 30 days to complete the current month.We need to find the current month KPI reputation average per company say today is 16-07-2021(system date) to 16-06-2021 is the current rating average KPI per company and then from 15-06-2021 to 15-05-2021 is previous month rating average KPI per company. I need to find the current month average rating KPI for the companies[A,B,C ,D] and previous month average rating KPI for the companies[A,B,C,D] . Could anyone please suggest any DAX to handle this ? My Input source table : Rating Company Date 2 A 16.07.2021 2 A 15.07.2021 2 A 13.07.2021 1 A 12.07.2021 -1 A 11.07.2021 0 A 10.07.2021 1 B 16.07.2021 1 B 15.07.2021 4 B 13.07.2021 2 B 12.07.2021 2 B 11.07.2021 -1 B 10.07.2021 1 C 16.07.2021 1 C 15.07.2021 4 C 13.07.2021 -2 C 12.07.2021 2 C 11.07.2021 3 C 10.07.2021 1 D 12.06.2021 4 D 11.06.2021 3 D 10.06.2021 1 B 10.06.2021 4 B 14.06.2021 2 B 15.06.2021 2 B 13.06.2021 -1 B 12.06.2021 1 C 14.06.2021 1 C 10.05.2021 4 C 12.05.2021 -2 C 11.05.2021 2 C 10.05.2021 3 C 11.05.2021 1 D 10.05.2021 4 D 11.05.2021 Kind regards SameerSolved723Views0likes1CommentDAX to calculate average benchmark of the ratings
Hi All, The rating of a vendor company is marked from the range 5 to -5 by customers as in the below source table. Rating column defines the rating per company per date and this date is for the whole year .I have added as a sample data for date in the below given range. I need to find the average Benchmark for ratings of the total companies[A,B,C,D] as stated below :- How can i find the average benchmark number for rating of the total companies in the market [A,B,C,D]? Could anyone suggest any DAX calculated measure or column to find this average benchmark in the below case scenario? Rating Company Date 2 A 14.07.2021 2 A 15.07.2021 2 A 13.07.2021 1 A 12.07.2021 -1 A 11.07.2021 0 A 10.07.2021 1 B 14.07.2021 1 B 15.07.2021 4 B 13.07.2021 2 B 12.07.2021 2 B 11.07.2021 -1 B 10.07.2021 1 C 14.07.2021 1 C 15.07.2021 4 C 13.07.2021 -2 C 12.07.2021 2 C 11.07.2021 3 C 10.07.2021 1 D 12.07.2021 4 D 11.07.2021 3 D 10.07.2021 Kind regards Sameer1.5KViews0likes2Comments