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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Oki
Helper I
Helper I

Show Data for the Latest Month BUT also let the user pick another

Hi, My name is Oki and im new here but already do a search with similar case and i still don't get my answer..
hope you guys can help.. here is my case

so, i have gauge that show a precentage data, what i need is that gauge show this month data as a default but user can also pick another month data (previous or next) with the column chart below (image).

 

Oki_0-1678678037107.png

 

and here is what i already try :

IF(MONTH(NOW())=[ThisMonth],CALCULATE(DIVIDE(SUM(MASTER[Achieve in Ton]),[TotalTargetDisti_Ton]),[ThisMonth]),DIVIDE(SUM(MASTER[Achieve in Ton]),[TotalTargetDisti_Ton]))

 

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@Oki Still seems like half the information and the tables aren't text so can't copy and paste into an Enter Data query and test out the code. So, winging it you would want to create 2 columns:

Month Year = FORMAT([Date],"mmm-yy")

Month Year Sort = FORMAT([Date],"yyyymm") + 0

Then maybe something like:

Gauge Measure = 
  VAR __MonthYear = MAX('Table'[Month Year Sort])
  VAR __Table = 
    SUMMARIZE(
      FILTER('Table',[Month Year Sort] = __MonthYear),
      "__Target", [Target in Ton Measure],
      "__Achieve", SUM('Table'[Achieve in Ton])
    )
  VAR __Percent = DIVIDE(MAXX(__Table,[__Achieve]), MAXX(__Table, [__Target]))
RETURN
  __Percent

Set your Sort By column for Month Year to Month Year Sort and use Month Year in your slicer. The theory here is that your table only contains data up until "current" so the MAX is always the "current" month. But, if they select something in the slicer (it is initally all values by default) then the MAX will return whatever they have chosen.

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Oki
Helper I
Helper I

Hi, @Greg_Deckler 
i want to say Thanks, cause it already solved..!
i just change in gauge measure :

 

VAR _MonthYear = MAX('Table'[MonthYearSort])

 

 into 

 

VAR _MonthYear = VALUE(FORMAT(TODAY(),"YYYYMM"))

 

Greg_Deckler
Community Champion
Community Champion

@Oki Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler 
if i describe in excel, the data is like this

 

Oki_0-1678680269851.png

 

the "1" table is original data
the "2" table is the precentage per month

what i want is the gauge will show the "Mar-23" data as the default which is "54%" because this month is "March" 
but if i have a slicer that contain "Dec-22", "Jan-23", "Feb-23", Mar-23". Then i click "Dec-22", the gauge will show "104%"

i hope this can help you understand what i need

Greg_Deckler
Community Champion
Community Champion

@Oki Still seems like half the information and the tables aren't text so can't copy and paste into an Enter Data query and test out the code. So, winging it you would want to create 2 columns:

Month Year = FORMAT([Date],"mmm-yy")

Month Year Sort = FORMAT([Date],"yyyymm") + 0

Then maybe something like:

Gauge Measure = 
  VAR __MonthYear = MAX('Table'[Month Year Sort])
  VAR __Table = 
    SUMMARIZE(
      FILTER('Table',[Month Year Sort] = __MonthYear),
      "__Target", [Target in Ton Measure],
      "__Achieve", SUM('Table'[Achieve in Ton])
    )
  VAR __Percent = DIVIDE(MAXX(__Table,[__Achieve]), MAXX(__Table, [__Target]))
RETURN
  __Percent

Set your Sort By column for Month Year to Month Year Sort and use Month Year in your slicer. The theory here is that your table only contains data up until "current" so the MAX is always the "current" month. But, if they select something in the slicer (it is initally all values by default) then the MAX will return whatever they have chosen.

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 
oh great! this exactly what i need,,
but the problem is my data till december 2023
is there a way to solved this?

here's the data sample

DateAchieve in TonTarget in Ton
29-Dec-22150      4.000
29-Dec-22150 
19-Dec-222.400 
19-Dec-221.440 
16-Jan-231.260      4.000
16-Jan-23420 
11-Jan-23480 
11-Jan-23480 
21-Feb-232.880      5.500
16-Feb-231.440 
23-Feb-23960 
24-Feb-23480 
1-Mar-23600      6.000
3-Mar-231.200 
8-Mar-231.440 
1-Apr-23       1.000
1-May-23       1.000



Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.