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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply

Dax formula

I have the following column I have created in Power BI: 

Active & Expired =
VAR SelectedQuarter = SELECTEDVALUE('Calender'[Quarter])
VAR SelectedQtrNo = LOOKUPVALUE('Calender'[Qtr No]'Calender'[Quarter]SelectedQuarter)
VAR EndQtrNo = LOOKUPVALUE('Calender'[Qtr No]'Calender'[Quarter]'Subscriptions Register'[End Quarter Value])

RETURN
    IF(EndQtrNo > SelectedQtrNo"Active","Expired")

The Active & Expired column only returns the Value for Active when it should have both? 

I tried debugging the measure and cant seem to find the issue

 

zameenakarmali_0-1728388525890.png

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @zameenakarmali ,

 

Since you only want to present these two columns, but in the previous reply Active/Expired was a measure, this would be difficult to achieve out of context, so I'll provide you with an alternative by recreating an Active/Expired calculated column.


To do this, I've made some changes to the original data:

1. Added a Sales column to Table.

vlinhuizhmsft_1-1729668147709.png

2. A new table named Status has been created:

vlinhuizhmsft_2-1729668207809.png

 

Then here are the specific steps:

1. Generate a new table, Table 2, which is the Cartesian product of the tables Table and Quarter.

 

Table 2 = CROSSJOIN('Table','Quarter')

 

vlinhuizhmsft_3-1729668377281.png

 

2. Create two new columns for Table 2.

QuarterNumber = LOOKUPVALUE(Dim_Date[Qtr No],Dim_Date[Quarter],'Table 2'[Quarter])

 

FinalActive/Expired3 = IF('Table 2'[QuarterNumber]>'Table 2'[End Quarter Number],"Active","Expired")

 

 

3. Create a new relationship:

vlinhuizhmsft_4-1729668596761.png

4. Create a measure:

 

Salesvalue = IF(SUM('Table 2'[Sales])=BLANK(),0,IF(HASONEVALUE('Table 2'[Quarter]),SUM('Table 2'[Sales])))

 

 

5. Create a slicer using the field Quarter from Table 2 and create a table using the field from Status and Salesvalue.

vlinhuizhmsft_5-1729668855611.png

vlinhuizhmsft_6-1729668873734.png

Best Regards,
Zhu
Community Support Team

 

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

View solution in original post

15 REPLIES 15
Anonymous
Not applicable

Thanks for the reply from bhanu_gautam.

 

Hi @zameenakarmali ,

 

Please try the following DAX:

Active & Expired =
VAR SelectedQuarter =
    MAX ( 'Calender'[Quarter] )
VAR SelectedQtrNo =
    LOOKUPVALUE ( 'Calender'[Qtr No], 'Calender'[Quarter], SelectedQuarter )
VAR EndQtrNo =
    LOOKUPVALUE (
        'Calender'[Qtr No],
        'Calender'[Quarter], 'Subscriptions Register'[End Quarter Value]
    )
RETURN
    IF ( EndQtrNo > SelectedQtrNo, "Active", "Expired" )

 

If the problem persists, can you provide a .pbix file with sensitive data removed? This will help locate your problem faster.

 

Best Regards,
Zhu
Community Support Team

 

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

 

Thanks, can you let me know how to upload a power bi file? 

Anonymous
Not applicable

Hi @zameenakarmali ,


you need to upload your file to a cloud storage (like OneDrive, Dropbox, Google Drive or Wetransfer for example) and paste the link to that storage location in the post. A friendly reminder to remember to protect your data privacy.

 

Best Regards,
Zhu

Anonymous
Not applicable

Hi @powerbiuser1111 , 

 

You may need to reset it again, I don't have permission to open your file. Thank you in advance for your efforts.

 

Best Regards,
Zhu

Can you try this link: 

 

Test File.pbix

 

Thanks so much

Anonymous
Not applicable

Hi  @powerbiuser1111 , 

Please refer to the following steps:

 

1.Create a new table, use it as a slicer field:

 vlinhuizhmsft_0-1729055747817.png

2.Create the relationships:

 vlinhuizhmsft_1-1729056065220.png

 

3.Create new measures:

Selected Quarter2 = LOOKUPVALUE('Dim_Date'[Qtr No],'Dim_Date'[Quarter],MAX('Quarter'[Quarter]))

 

Active/Expired2 = IF(ISINSCOPE('Quarter'[Quarter]),IF([Selected Quarter2]<CALCULATE(MAX('Table'[End Quarter Number]),REMOVEFILTERS('Dim_Date')),"Active","Expired"))

 

4.The result is as follows:

vlinhuizhmsft_2-1729056360294.png

 

By the way, If you want to compare Starting Quarter and End Quarter in your table you can create two more calculated columns:

 

Start Quarter Number = LOOKUPVALUE('Dim_Date'[Qtr No],'Dim_Date'[Quarter],'Table'[Starting Quarter])

 

Active/Expired3 = IF('Table'[Start Quarter Number]<'Table'[End Quarter Number],"Active","Expired")

 

Result:

vlinhuizhmsft_0-1729057228943.png

Best Regards,
Zhu
Community Support Team

 

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

Thanks for that, 

 

If I also have a Sales amount for each contract, and I would like to show just the Sum of Sales for Active and Expired Contracts, how would I do that?

Anonymous
Not applicable

Hi  @zameenakarmali , 

 

As shown in the image, I added two columns of Contract ID as well as Sales to the original Table:

vlinhuizhmsft_1-1729218180524.png

 

Then create a measure, use the ALL function to remove all filters to get all active and expired contract sales:

 

Salesamount = CALCULATE(SUM('Table'[Sales]),ALL('Table'))
 
The result is as follows:

vlinhuizhmsft_2-1729218378099.png

Best Regards,
Zhu

 

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

 

I would like to show a table like below: 

 

The sales amount would change depending on the Selected value of the Quarter.

zameenakarmali_0-1729518460504.png

 

Anonymous
Not applicable

Hi @zameenakarmali ,

 

Since you only want to present these two columns, but in the previous reply Active/Expired was a measure, this would be difficult to achieve out of context, so I'll provide you with an alternative by recreating an Active/Expired calculated column.


To do this, I've made some changes to the original data:

1. Added a Sales column to Table.

vlinhuizhmsft_1-1729668147709.png

2. A new table named Status has been created:

vlinhuizhmsft_2-1729668207809.png

 

Then here are the specific steps:

1. Generate a new table, Table 2, which is the Cartesian product of the tables Table and Quarter.

 

Table 2 = CROSSJOIN('Table','Quarter')

 

vlinhuizhmsft_3-1729668377281.png

 

2. Create two new columns for Table 2.

QuarterNumber = LOOKUPVALUE(Dim_Date[Qtr No],Dim_Date[Quarter],'Table 2'[Quarter])

 

FinalActive/Expired3 = IF('Table 2'[QuarterNumber]>'Table 2'[End Quarter Number],"Active","Expired")

 

 

3. Create a new relationship:

vlinhuizhmsft_4-1729668596761.png

4. Create a measure:

 

Salesvalue = IF(SUM('Table 2'[Sales])=BLANK(),0,IF(HASONEVALUE('Table 2'[Quarter]),SUM('Table 2'[Sales])))

 

 

5. Create a slicer using the field Quarter from Table 2 and create a table using the field from Status and Salesvalue.

vlinhuizhmsft_5-1729668855611.png

vlinhuizhmsft_6-1729668873734.png

Best Regards,
Zhu
Community Support Team

 

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

If I was only to show the Sales Amount and the Active/Expired column would that work?

Thanks for the suggestion but this still didnt seem to work 

bhanu_gautam
Super User
Super User

@zameenakarmali , Try using below DAX

 

Active & Expired =
VAR SelectedQuarter = SELECTEDVALUE('Calender'[Quarter])
VAR SelectedQtrNo = LOOKUPVALUE('Calender'[Qtr No], 'Calender'[Quarter], SelectedQuarter)
VAR EndQtrNo = CALCULATE(
LOOKUPVALUE('Calender'[Qtr No], 'Calender'[Quarter], 'Subscriptions Register'[End Quarter Value])
)
RETURN
IF(EndQtrNo > SelectedQtrNo, "Active", "Expired")




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Thanks for this, it still doesnt work, 

 

I am assuming the issue is because the End Quarter Value is a column field and the selected value is a measure that only has one value?

 

zameenakarmali_0-1728558667455.png

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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