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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
PeterStuhr
Helper V
Helper V

Count Year to Date and LTM

Hi,

 

I am fairly new to Power BI and DAX in general.

 

I have a table with Opportunities, containg a "status" field "Won/Lost/Open".

 

I would like to calculate the Winrate (Count of Won opps / Count of Won+Lost Opps). I would like this for "Year to date" and "Last 12 months".

 

Any advice would be appreciated!

1 ACCEPTED SOLUTION

@PeterStuhr 

 

Mistake in the code. Needs >= instead of <=

 

Last12MonthsMeasure =
CALCULATE (
    DIVIDE (
        CALCULATE ( COUNT ( Table1[Status] ), Table1[Status] = "Won" ),
        CALCULATE ( COUNT ( Table1[Status] ), Table1[Status] IN { "Won", "Lost" } )
    ),
    Table1[CloseDate] >= EDATE ( TODAY (), -12 )
)

.

View solution in original post

5 REPLIES 5
AlB
Super User
Super User

Hi @PeterStuhr 

 

You need to show the structure of your tables and sample data to help people trying to answer. Otherwise they have to make guesses. Please show your sample data in text-tabular format in addition to (or instead of) the screen captures. Just use 'Copy table' in Power BI and paste it here.

 

Do you have a date table? Is there a date column in your table?

'Year to date' for what year, until what date?' 'Last 12 months' from when?

 

 

Hi @AI 

 

Thanks for your comment.

I hope this is what you mean:

 

OpportunityStatusCreateDateCreateMonthCreateYearCreateYearMonthCloseDateCloseMonthCloseYearCloseYearMonth
XAWon01-01-2017120172017-131-01-2017120172017-1
XBWon02-01-2017120172017-101-02-2017220172017-2
XCOpen03-01-2017120172017-1    
XDLost04-01-2017120172017-103-02-2017220172017-2
XELost05-01-2017120172017-104-02-2017220172017-2
XFWon06-02-2017220172017-208-03-2017320172017-3
XGLost07-02-2017220172017-209-03-2017320172017-3
XHWon13-02-2017220172017-215-03-2017320172017-3
XILost20-02-2017220172017-222-03-2017320172017-3
XJWon15-02-2017220172017-217-03-201732017

2017-3

 

it looks similar to this.

 

"Year To date" should be Jan-1 till Today, and "Last 12 months" should be from Feb15-18 till today. So should always be real time, if that makes sense.

@PeterStuhr 

 

I guess you want to take into account the CloseDate to determine the month in which you count the opportunity. Otherwise you can just change Table1[CloseDate] for Table1[CreateDate] in the code below.  You can create two measures as follows and place them, for instance, in a card visual. Table1 is the table you show.

 

 

Last12MonthsMeasure =
CALCULATE (
    DIVIDE (
        CALCULATE ( COUNT ( Table1[Status] ), Table1[Status] = "Won" ),
        CALCULATE ( COUNT ( Table1[Status] ), Table1[Status] IN { "Won", "Lost" } )
    ),
    Table1[CloseDate] <= EDATE ( TODAY (), -12 )
)

   

 

Year2DateMeasure =
CALCULATE (
    DIVIDE (
        CALCULATE ( COUNT ( Table1[Status] ), Table1[Status] = "Won" ),
        CALCULATE ( COUNT ( Table1[Status] ), Table1[Status] IN { "Won", "Lost" } )
    ),
    YEAR ( Table1[CloseDate] ) = YEAR ( TODAY () )
)

 

You might have to use ";" instead of  "," in the code above depending on your OS locale settings

Hi @AlB 

 

Thanks a lot. I can make the YTD one work.

Unfortunately, my "Last 12 months" seems to calculate a bit wrong compared to when I do it manually. I cant seem to find the reason.. I did this:

 

WinRate LTM = CALCULATE ( DIVIDE ( CALCULATE ( COUNT ( CRMOpportunities[OpportunityStatus] ); CRMOpportunities[OpportunityStatus] = "Won" ); CALCULATE ( COUNT ( CRMOpportunities[OpportunityStatus] ); CRMOpportunities[OpportunityStatus] IN { "Won"; "Lost" } ) ); CRMOpportunities[OpportunityCloseDate] <= EDATE(TODAY();-12))

@PeterStuhr 

 

Mistake in the code. Needs >= instead of <=

 

Last12MonthsMeasure =
CALCULATE (
    DIVIDE (
        CALCULATE ( COUNT ( Table1[Status] ), Table1[Status] = "Won" ),
        CALCULATE ( COUNT ( Table1[Status] ), Table1[Status] IN { "Won", "Lost" } )
    ),
    Table1[CloseDate] >= EDATE ( TODAY (), -12 )
)

.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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