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
dbrandone
Helper III
Helper III

Need Help with Dax formula to pull Use percentage of last month only

I have hit a wall in figuring out the correct dax formula to get the last month's use percentage to show up through a measure. I need to pull a list of the item numbers(unique identifiers) that were created last month, then take those numbers and based on whether they were used or not, determine a percentage that were used. I have the item number and created date in one table. I then have the item number and whether the item was used or not used in another table. I thought determining the list of the items created first as a variable would be best, but I can summarize columns, but getting the correct formula to take the current date and then subtract one month and then pull a list of the items with the item numbers for that month. From there I would use that variable to use on the second table and then divide the two numbers, not used versus used. 

 

I have been waiting for that aha moment with dax to where I can read and write proficiently in it and the format makes sense, but it has not happened yet. Hopefully soon!! any tips or explanations would be greatly appreciated.

1 ACCEPTED SOLUTION

@dbrandone,

 

This measure is based on today's date:

 

Percent Used Last Month = 
VAR vToday =
    TODAY ()
VAR vEndDate =
    EOMONTH ( vToday, -1 )
VAR vStartDate =
    EOMONTH ( vToday, -2 ) + 1
VAR vNumerator =
    CALCULATE (
        [Count Item],
        Table2[Outcome] = "Used",
        DATESBETWEEN ( DimDate[Date], vStartDate, vEndDate )
    )
VAR vDenominator =
    CALCULATE ( [Count Item], DATESBETWEEN ( DimDate[Date], vStartDate, vEndDate ) )
VAR vResult =
    DIVIDE ( vNumerator, vDenominator )
RETURN
    vResult




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

8 REPLIES 8
DataInsights
Super User
Super User

@dbrandone,

 

Would you be able to provide sample data or a link to your pbix?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




So below is an example of the data I have in two seperate tables. I need to pull the ID numbers that are tied to the previous month(In this example, lets say that the previous month is February) from Table 1 and then take their outcome from table 2 and find the Used percentage. I can quite easily take the outcome and put it in the same table as 1 and that is what I did today. I know SQL code very well, but DAX is kicking my butt as I cant wrap my head around to format and foundation of its thinking.

 

Table 1 Table 2
UniqueIdentifierItem Made on Unique IdentifierOutcome
11/3/2021 1Used
21/5/2021 2Used
31/7/2021 3NotUsed
41/9/2021 4Used
51/11/2021 5NotUsed
61/13/2021 6NotUsed
71/15/2021 7NotUsed
81/17/2021 8Used
91/19/2021 9Used
101/21/2021 10Used
111/23/2021 11Used
121/25/2021 12Used
131/27/2021 13NotUsed
141/29/2021 14NotUsed
151/31/2021 15Used
162/2/2021 16Used
172/4/2021 17Used
182/6/2021 18NotUsed
192/8/2021 19NotUsed
202/10/2021 20Used
212/12/2021 21Used
222/14/2021 22Used
232/16/2021 23NotUsed
242/18/2021 24NotUsed
252/20/2021 25Used
262/22/2021 26Used
272/24/2021 27Used
282/26/2021 28NotUsed
292/28/2021 29NotUsed
303/2/2021 30Used
313/4/2021 31Used

@dbrandone,

 

Try this solution.

 

1. Create data model with a date table:

 

DataInsights_1-1625094355280.png

 

2. Create measures:

 

Count Item = COUNT ( Table1[Unique Identifier] )

Percent Used =
VAR vNumerator =
    CALCULATE ( [Count Item], Table2[Outcome] = "Used" )
VAR vDenominator = [Count Item]
VAR vResult =
    DIVIDE ( vNumerator, vDenominator )
RETURN
    vResult

 

3. Result:

 

DataInsights_2-1625094576154.png

 

You can add a date slicer to filter the visual by the selected Month Year.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




This is great. Thanks.

 

If I wanted to put a card on the dashboard that is titled "Used % last month" or even "Used % in the last 30 days", that is something that I have struggled with. Now that I have the "vResult", would it just be:

                                Previous Month Used % = PreviousMonth(vResult)

@dbrandone,

 

How are you defining "last month"? Is it specified by the user in a slicer, or based on today's date?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Today's Date.

 

I have wrestled with this as to either just show the previous month. For example, today is 7/1, so today would be the first day the card would show data from 6/1-6/30.

 

or

 

Should I do the used % of the last 30 days and it is constantly moving. Leaning towards the previous month from a data use need.

@dbrandone,

 

This measure is based on today's date:

 

Percent Used Last Month = 
VAR vToday =
    TODAY ()
VAR vEndDate =
    EOMONTH ( vToday, -1 )
VAR vStartDate =
    EOMONTH ( vToday, -2 ) + 1
VAR vNumerator =
    CALCULATE (
        [Count Item],
        Table2[Outcome] = "Used",
        DATESBETWEEN ( DimDate[Date], vStartDate, vEndDate )
    )
VAR vDenominator =
    CALCULATE ( [Count Item], DATESBETWEEN ( DimDate[Date], vStartDate, vEndDate ) )
VAR vResult =
    DIVIDE ( vNumerator, vDenominator )
RETURN
    vResult




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Give me a second to give you a data example. We deal with very sensitive data so I will see what we can do

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.