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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
fnyameino
Frequent Visitor

Create a custom static table using DAX

I am trying to design this chart in powerbi. The x axis contains different time limits. 

fnyameino_0-1670106194471.png

Currently this is design in excel and the table below is the source of data

 

Average Tests 
March2
April 1 - 284
April 29 - July 1756
July 20 - Oct 9, 202063
Oct 12 2020-Nov 11, 202215

 

This table is created after getting average test from the same column on a different table below

DateNumber of Tests
03/09/201
03/10/202
03/11/201
03/12/200

 

Currently powerbi has access to the primary dataset below

Date | Name| Race/Ethnicity | Result

 

My inital thought was using DAX ROW or DATATABLE to create a Virtual or static table and use the average function to get the numbers. I am stuck!!! I will honestly appreciate any help provided.

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @fnyameino

If your categorization is static, the easiest way would be to add a category column in your record table. Then you could  pull the category column to your plotting x-axis. 

 

the code to add the column looks like this:

 

Category =

SWICH(

    TRUE(),

    "March", TableName[Date]<=DATE(2020,3,31),

    "April 1- 28", TableName[Date]<=DATE(2020,4,28),

    "April 29- July 17", TableName[Date]<=DATE(2020,7,17),

    "July 20- Oct 9 2020", TableName[Date]>=DATE(2020,7,20)&&TableName[Date]<=DATE(2020,10,9),

    "Oct 12 2020- Nov 11, 2022", TableName[Date]>=DATE(2020,10,12)&&TableName[Date]<=DATE(2022,11,11)

)

 

if you have a dynamic grouping, say the way of categorization changes periodically and you find the change in DAX code is an issue, you may import the category table into Power BI and related with the record table. 

 

View solution in original post

2 REPLIES 2
FreemanZ
Super User
Super User

hi @fnyameino

If your categorization is static, the easiest way would be to add a category column in your record table. Then you could  pull the category column to your plotting x-axis. 

 

the code to add the column looks like this:

 

Category =

SWICH(

    TRUE(),

    "March", TableName[Date]<=DATE(2020,3,31),

    "April 1- 28", TableName[Date]<=DATE(2020,4,28),

    "April 29- July 17", TableName[Date]<=DATE(2020,7,17),

    "July 20- Oct 9 2020", TableName[Date]>=DATE(2020,7,20)&&TableName[Date]<=DATE(2020,10,9),

    "Oct 12 2020- Nov 11, 2022", TableName[Date]>=DATE(2020,10,12)&&TableName[Date]<=DATE(2022,11,11)

)

 

if you have a dynamic grouping, say the way of categorization changes periodically and you find the change in DAX code is an issue, you may import the category table into Power BI and related with the record table. 

 

This worked the magic

Category =
VAR DateNow = TODAY()
RETURN
SWITCH(
    TRUE(),
    CovidTesting[Date]<=DATE(2020,3,31),"1. March" ,
    CovidTesting[Date]<=DATE(2020,4,28), "2. April 1-28",
    CovidTesting[Date]<=DATE(2020,7,17), "3. April 29-July 17",
    CovidTesting[Date]>=DATE(2020,7,20)&&CovidTesting[Date]<=DATE(2020,10,9), "4. July 20-Oct 9 2020",
    CovidTesting[Date]>=DATE(2020,10,12)&&CovidTesting[Date]<= TODAY(),"5. Oct 12 2020-Dec 13 2022"

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Power BI Header Change

Power BI Header Update

Read about the exciting updates for the Power BI forum.

Top Solution Authors