Dax based on the result you obtained, you can use the following dax
RESPONSE ADDITION QUERY: please note that I have slicer with the values of oper day, and it is taking a proximate a one month of a period
Download 28.24 Kb.
|
Dax documents
RESPONSE ADDITION QUERY: please note that I have slicer with the values of oper day, and it is taking a proximate a one month of a period
ANSWER To adjust the previous month's measure based on the slicer selection, you can modify the DAX measure as follows: 1. Define a new measure called "Previous Month Last Working Day" that finds the last working day of the previous month based on the slicer selection: dax Previous Month Last Working Day = CALCULATE ( MAX ( 'new_DIM_SBD_DEP_ACC_M'[OPER_DAY] ), 'new_DIM_SBD_DEP_ACC_M'[OPER_DAY] <= EOMONTH ( MIN ( 'new_DIM_SBD_DEP_ACC_M'[OPER_DAY] ), -2 ), DAY ( 'new_DIM_SBD_DEP_ACC_M'[OPER_DAY] ) <> 0, WEEKDAY ( 'new_DIM_SBD_DEP_ACC_M'[OPER_DAY] ) <> 1 ) This measure uses the "MIN" function to get the minimum OPER_DAY value from the slicer selection. It then calculates the maximum OPER_DAY value that is less than or equal to the last day of the previous month, excluding any days with a day number of zero or a weekday number of 1 (Sunday). 2. Modify your existing measure "Ой бошидаги колдик KPI" to use the "Previous Month Last Working Day" measure dynamically based on the slicer selection: dax Ой бошидаги колдик KPI = CALCULATE ( SUM ( new_DIM_SBD_DEP_ACC_M[SUM_DEP] ), 'new_DIM_SBD_DEP_ACC_M'[OPER_DAY] = [Previous Month Last Working Day] ) This modified measure uses the calculated "Previous Month Last Working Day" measure as the filter condition to retrieve the sum of SUM_DEP for the last working day of the previous month, which is dynamically determined based on the slicer selection. With these adjustments, your measure will consider the slicer selection and provide the correct value for the last working day of the previous month within the selected period. Hi again! EDNA.AI Hello! How can I assist you today? RESPONSE: "MINX(FILTER('new_DIM_SBD_DEP_ACC_M', 'new_DIM_SBD_DEP_ACC_M'[OPER_DAY] IN ALLSELECTED('new_DIM_SBD_DEP_ACC_M'[OPER_DAY])), 'new_DIM_SBD_DEP_ACC_M'[OPER_DAY])+1" I am using this measure to find the first day of the month, note that in slicer filter which starts from the max working day of the last month to the max working day of the current month, but +1 is not always returning to the first day of the month, because if the last month's last working day was 27 then measure returns to 28-th day, but I want it to find next month’s first day no matter if the first day is working day or not, I have to get the first date, so please help me to fix this measure using dax! ANSWER: To fix your measure and always return the first day of the next month, you can modify it using the following DAX expression: dax NEXT_MONTH_FIRST_DAY = DATE ( YEAR ( MAX ( 'new_DIM_SBD_DEP_ACC_M'[OPER_DAY] ) ), MONTH ( MAX ( 'new_DIM_SBD_DEP_ACC_M'[OPER_DAY] ) ) + 1, 1 ) This measure uses the "DATE" function to construct a new date value. The year is obtained using the "YEAR" function on the maximum OPER_DAY value, which represents the current month. Then, the month is incremented by 1 using the "MONTH" function, ensuring that we get the next month. Finally, the day is set to 1 to get the first day of that month. By utilizing this modified measure, you will consistently retrieve the first day of the next month, regardless of whether it is a working day or not. RESPONSE ++ Now I want it to find current months max date no matter of working day or not To find the maximum date of the current month, regardless of whether it is a working day or not, you can modify your DAX expression using the following measure: dax CURRENT_MONTH_MAX_DATE = EOMONTH(MAX('new_DIM_SBD_DEP_ACC_M'[OPER_DAY]), 0) This measure uses the "MAX" function to retrieve the maximum OPER_DAY value from your 'new_DIM_SBD_DEP_ACC_M' table, representing the current month. Then, it uses the "EOMONTH" function with a second argument of 0 to get the last day of that month. By implementing this modified measure, you will obtain the maximum date of the current month, irrespective of whether it is a working day or not. SQL QUERY FOR THIS DAX! Ой охиридаги колдик = VAR startmonth = MAXX ( FILTER ( 'new_DIM_SBD_DEP_ACC_M', 'new_DIM_SBD_DEP_ACC_M'[OPER_DAY] IN ALLSELECTED ( 'new_DIM_SBD_DEP_ACC_M'[OPER_DAY] ) && ISBLANK ( 'new_DIM_SBD_DEP_ACC_M'[CLOSING_DATE] ) ), 'new_DIM_SBD_DEP_ACC_M'[OPER_DAY] ) RETURN CALCULATE ( SUM ( new_DIM_SBD_DEP_ACC_M[SUM_DEP] ), 'new_DIM_SBD_DEP_ACC_M'[OPER_DAY] = startmonth, ISBLANK ( 'new_DIM_SBD_DEP_ACC_M'[CLOSING_DATE] ) || ISFILTERED ( 'new_DIM_SBD_DEP_ACC_M'[OPER_DAY] ) && NOT ( ISBLANK ( 'new_DIM_SBD_DEP_ACC_M'[OPER_DAY] ) ), ALL ( 'new_DIM_SBD_DEP_ACC_M'[OPER_DAY] ) ) ...…………………………………………………………………………………………………………………………………………………………………... SELECT ACC, FILIAL_CODE, SUM(SUM_DEP) AS [Ой охиридаги колдик] FROM new_DIM_SBD_DEP_ACC_M t1 WHERE t1.OPER_DAY = ( SELECT MAX(OPER_DAY) FROM new_DIM_SBD_DEP_ACC_M t2 WHERE t2.OPER_DAY IN ( SELECT OPER_DAY FROM new_DIM_SBD_DEP_ACC_M WHERE CLOSING_DATE IS NULL AND OPER_DAY BETWEEN '2023-08-01' AND '2023-08-31' ) ) AND ( t1.CLOSING_DATE IS NULL OR ( t1.OPER_DAY IN ( SELECT OPER_DAY FROM new_DIM_SBD_DEP_ACC_M WHERE OPER_DAY IS NOT NULL AND OPER_DAY IN ( SELECT OPER_DAY FROM new_DIM_SBD_DEP_ACC_M WHERE OPER_DAY BETWEEN '2023-08-01' AND '2023-08-31' GROUP BY OPER_DAY ) ) AND t1.OPER_DAY IS NOT NULL ) ) GROUP BY ACC, FILIAL_CODE Download 28.24 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling