Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
vivek_babu
Advocate I
Advocate I

DAX Calculated Column Issue

Hi All,

 

I am trying to calculate the previous average coverage percentage based on the reporting date and system name columns. The formula i used below works if i dont consider system name to get the previous average coverage for the previous reporting dates. But, i want to get the previous average coverage percentage for each system name and its previous reporting dates. 

Screenprint:

 

 

vivek_babu_0-1731335990230.png

 

Actual output i am expecting,

 

Formula:

Previous_Percentage_Coverage =
var currentdate = DEEP_SECURITY[REPORTING_DATE]
var previousdate = MAXX(FILTER(ALL(DEEP_SECURITY),DEEP_SECURITY[REPORTING_DATE] < currentdate),DEEP_SECURITY[REPORTING_DATE])
var currentsysname = max(DEEP_SECURITY[SYSTEM_NAME])
var previoussysname = MAXX(FILTER(ALL(DEEP_SECURITY),DEEP_SECURITY[SYSTEM_NAME] <> currentsysname),DEEP_SECURITY[SYSTEM_NAME])
RETURN
MAXX(FILTER(ALL(DEEP_SECURITY),DEEP_SECURITY[REPORTING_DATE] = previousdate && DEEP_SECURITY[SYSTEM_NAME] <> previoussysname
),
DEEP_SECURITY[avg_percentage_covered])
Please check and let me know how to correct the formula to get the desired result 
 
Regards
Vivek N
1 ACCEPTED SOLUTION
v-jialongy-msft
Community Support
Community Support

Hi @vivek_babu 

Please try the follow dax:

Previous_Percentage_Coverage = 
var currentdate = DEEP_SECURITY[REPORTING_DATE]
var previousdate = MAXX(FILTER(ALL(DEEP_SECURITY),DEEP_SECURITY[REPORTING_DATE] < currentdate),DEEP_SECURITY[REPORTING_DATE])
var currentsysname = max(DEEP_SECURITY[SYSTEM_NAME])
RETURN
MAXX(FILTER(ALL(DEEP_SECURITY),DEEP_SECURITY[REPORTING_DATE] = previousdate && DEEP_SECURITY[SYSTEM_NAME] = EARLIER(DEEP_SECURITY[SYSTEM_NAME])
),
DEEP_SECURITY[avg_percentage_covered])

 

 

Result:

vjialongymsft_0-1731395012949.png

 

 

 

 

 

Best Regards,

Jayleny

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-jialongy-msft
Community Support
Community Support

Hi @vivek_babu 

Please try the follow dax:

Previous_Percentage_Coverage = 
var currentdate = DEEP_SECURITY[REPORTING_DATE]
var previousdate = MAXX(FILTER(ALL(DEEP_SECURITY),DEEP_SECURITY[REPORTING_DATE] < currentdate),DEEP_SECURITY[REPORTING_DATE])
var currentsysname = max(DEEP_SECURITY[SYSTEM_NAME])
RETURN
MAXX(FILTER(ALL(DEEP_SECURITY),DEEP_SECURITY[REPORTING_DATE] = previousdate && DEEP_SECURITY[SYSTEM_NAME] = EARLIER(DEEP_SECURITY[SYSTEM_NAME])
),
DEEP_SECURITY[avg_percentage_covered])

 

 

Result:

vjialongymsft_0-1731395012949.png

 

 

 

 

 

Best Regards,

Jayleny

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-jialongy-msft 

Thank you for providing the solution!  It worked and i am getting the desired outcome now!

 

Please check below,

vivek_babu_0-1731399459236.png

 

I appreciate your help and thanks once again 🙂

 

Regards

Vivek N




 

vivek_babu
Advocate I
Advocate I

Hi @saud968 

 

Thanks for providing your solution. I tried your solution but i am getting blanks as output,


Screenshot:

vivek_babu_0-1731346691924.png

 

@lbendlin @vojtechsima @v-xianjtan-msft  @amitchandak @rajendraongole1 @danextian @Ritaf1983 @johnt75 @shafiz_p @FreemanZ 

 

Regards

Vivek N

hi @vivek_babu ,

 

try like:

column =

VAR _name = [NAME]

VAR _date = [DATE]

RETURN

MAXX(

    TOPN(

       1,

       FILTER(

           DEEP, 

           DEEP[DATE]<_date

              &&DEEP[NAME]=_name

       ),

       DEEP[DATE]

   ),

   DEEP[avg]

)

Hi @FreemanZ 

 

Thanks for providing solution. Unfortunately, its not giving me the desired outcome. I am getting blanks and incorrect values so please check below,

 

Formula:

Prev_Perc =
var _name = DEEP_SECURITY[SYSTEM_NAME]
var _date = DEEP_SECURITY[REPORTING_DATE]
RETURN
MAXX(
    TOPN(
        1,FILTER(DEEP_SECURITY,DEEP_SECURITY[REPORTING_DATE] < _date && DEEP_SECURITY[SYSTEM_NAME] < _name
        ),
        DEEP_SECURITY[REPORTING_DATE]
    ),
    DEEP_SECURITY[avg_percentage_covered]
)
 
Screenshot:
vivek_babu_0-1731399136780.png


Regards

Vivek N


vivek280393
New Member

Hi All,

 

I am trying to calculate the previous average percentage column based on reporting date and system name columns. 

The formula is working when i use reporting date alone to get the previous average percentage but i have to consider the system name so the average needs to be done for each system name and then calcualte the previous reporting date but i am not getting the desired result. 

 

Screenshot:

vivek280393_1-1731334730731.png

 

Formula used:

Previous_Percentage_Coverage =
var currentdate = DEEP_SECURITY[REPORTING_DATE]
var previousdate = MAXX(FILTER(ALL(DEEP_SECURITY),DEEP_SECURITY[REPORTING_DATE] < currentdate),DEEP_SECURITY[REPORTING_DATE])
var currentsysname = max(DEEP_SECURITY[SYSTEM_NAME])
var previoussysname = MAXX(FILTER(ALL(DEEP_SECURITY),DEEP_SECURITY[SYSTEM_NAME] <> currentsysname),DEEP_SECURITY[SYSTEM_NAME])
RETURN
MAXX(FILTER(ALL(DEEP_SECURITY),DEEP_SECURITY[REPORTING_DATE] = previousdate && DEEP_SECURITY[SYSTEM_NAME] <> previoussysname
),
DEEP_SECURITY[avg_percentage_covered])
 
Actual output i am expecting is below,

Percentage CoverageReporting DateSystem NamePrevious Percentage Coverage
85.297/1/2018DS AWS 2.0 
95.57/1/2018DS AWS 1.0 
90.488/1/2018DS AWS 2.085.29
92.868/1/2018DS AWS 1.095.5

 

Please check and let me know where is the issue

 

@vojtechsima @v-xianjtan-msft @lbendlin @amitchandak @rajendraongole1 @Ritaf1983 @danextian @shafiz_p @FreemanZ @johnt75 

 

Regards

Vivek N

saud968
Solution Sage
Solution Sage

Try this Dax 

Previous_Percentage_Coverage =
VAR currentdate = DEEP_SECURITY[REPORTING_DATE]
VAR currentsysname = DEEP_SECURITY[SYSTEM_NAME]
VAR previousdate = MAXX(
FILTER(
ALL(DEEP_SECURITY),
DEEP_SECURITY[REPORTING_DATE] < currentdate &&
DEEP_SECURITY[SYSTEM_NAME] = currentsysname
),
DEEP_SECURITY[REPORTING_DATE]
)
RETURN
CALCULATE(
MAX(DEEP_SECURITY[avg_percentage_covered]),
DEEP_SECURITY[REPORTING_DATE] = previousdate,
DEEP_SECURITY[SYSTEM_NAME] = currentsysname
)

Best Regards
Saud Ansari
If this post helps, please Accept it as a Solution to help other members find it. I appreciate your Kudos!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.