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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
MarkEvansHW
Helper II
Helper II

Slicer to select "group by" field in table

I have table like this:

quartermonthweekdatesales
2020-Q32020-092020-352020-09-01$14,43.85
2020-Q32020-082020-352020-08-31$32,432.32
2020-Q32020-082020-352020-08-30$986.45
2020-Q32020-082020-342020-08-29$11,344.00
...............

 

Here's an image of above table as it is displaying incorrectly in my browser:

MarkEvansHW_0-1600183367044.png

 

 

I have a slicer that allows the user to pick between "quarter", "month", week", and "date".

 

I'd like the resulting table to include a field (with no summary function) that groups by the appropriate period field based on the selection. In the example below, the user has selected "quarter":

 

Period (dynamic)sales (sum)
2020-Q3$983,324.23
2020-Q2 ...etc

 

Here's an image of above table:

MarkEvansHW_1-1600183415149.png

 

 

 

Perhaps further complicating this is that the source tables are "Direct Query". Thanks for your suggestions.

 

5 REPLIES 5
v-stephen-msft
Community Support
Community Support

Hi @MarkEvansHW ,

 

Create a Category table for slicer. There is no relationship between two tables.

8.png

9.png

 

Then try this measure.

Period = 
SWITCH (
    SELECTEDVALUE ( Category[Category] ),
    "date", MAX ( 'Table'[date] ),
    "month", MAX ( 'Table'[month] ),
    "quarter", MAX ( 'Table'[quarter] ),
    "week", MAX ( 'Table'[week] )
)

result dynamic slicer.gif

 

You can check more details from here.

 

Best Regards,

Stephen Tao

 

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

I see - it is because in your fact table, the sales column is a text field and in the table visual you're showing it is "not summarized". I need for this to be a numeric field that sums in the solution. Thanks for the suggestion.

I'm trying to get it to summarize by the different levels. In your demo, the rows are not totalling for quarter, month, etc. There should be one row for the quarter, two rows for the months and so on.

 

I'm not actually sure how you're getting more than one row, tbh. When I implement similar solution, I get the MAX date for the given period type (day, week, month, etc) and it returns one row with that max date and the total sum of the other field.

Greg_Deckler
Super User
Super User

@MarkEvansHW In general, to use a measure in that way, you need to use the Disconnected Table Trick as this article demonstrates: https://community.powerbi.com/t5/Community-Blog/Solving-Attendance-with-the-Disconnected-Table-Trick...


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Yes, I have a measure that works that way using the disconnected table. However, I don't see any way to have a non-measure (not use SUM, MIN, MAX, etc) in a field in the resulting table. Thanks.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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