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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
spizzo
Regular Visitor

Creating table like sql trigger in Power BI ?

Hi all folks!

 

Here a little example of a sql trigger for creating and updating a table with fetch cycle in sql server:

 

/*inizio ciclo principale*/
DECLARE @AMBIENTE_max VARCHAR(50) ;
DECLARE @IDCOMPANY_max VARCHAR(50) ;
DECLARE @IDEMPLOY_max VARCHAR(50) ;
declare my_cursor_max cursor for select DISTINCT AMBIENTE, IDCOMPANY,IDEMPLOY from ZSW_TMP_EMPLOY_1 group by AMBIENTE, IDCOMPANY,IDEMPLOY;
open my_cursor_max;
FETCH NEXT FROM MY_CURSOR_max INTO @AMBIENTE_max,@IDCOMPANY_max,@IDEMPLOY_max;
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT 'Ambiente: '+RTRIM(CAST(@ambiente_max as VARCHAR(50)))
PRINT 'Azienda: '+RTRIM(CAST(@idcompany_max as VARCHAR(50)))
PRINT 'Dipendente: '+RTRIM(CAST(@idemploy_max as VARCHAR(50)))

/*ciclo interno per ogni singolo dipendente */
DECLARE @AMBIENTE VARCHAR(50) ;
DECLARE @IDCOMPANY VARCHAR(50) ;
DECLARE @IDEMPLOY VARCHAR(50) ;
DECLARE @DATA_INIZIO DATETIME ;
DECLARE @DATA_FINE DATETIME ;
DECLARE @PREV_DATA_INIZIO DATETIME;
SET @PREV_DATA_INIZIO = NULL;
declare my_cursor cursor for select DISTINCT AMBIENTE, IDCOMPANY,IDEMPLOY,DATA_INIZIO, DATA_FINE from ZSW_TMP_EMPLOY_1 where AMBIENTE=@AMBIENTE_max and IDCOMPANY=@IDCOMPANY_max and IDEMPLOY=@IDEMPLOY_max ORDER BY DATA_INIZIO DESC;
open my_cursor;
FETCH NEXT FROM MY_CURSOR INTO @AMBIENTE,@IDCOMPANY,@IDEMPLOY,@DATA_INIZIO, @DATA_FINE;
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT 'DATA INIZIO: '+RTRIM(CAST(@DATA_INIZIO as VARCHAR(50)))
PRINT 'DATA PRECEDENTE INIZIO: '+RTRIM(CAST(@PREV_DATA_INIZIO as VARCHAR(50)))
PRINT 'DATA FINE: '+RTRIM(CAST(@DATA_FINE as VARCHAR(50)))
UPDATE ZSW_TMP_EMPLOY_1 SET DATA_FINE=@PREV_DATA_INIZIO WHERE AMBIENTE=RTRIM(@AMBIENTE) AND IDCOMPANY=RTRIM(@IDCOMPANY) AND IDEMPLOY=RTRIM(@IDEMPLOY) AND DATA_INIZIO=@DATA_INIZIO;
SET @PREV_DATA_INIZIO = CAST(@DATA_INIZIO-1 AS DATETIME);
FETCH NEXT FROM MY_CURSOR INTO @AMBIENTE,@IDCOMPANY,@IDEMPLOY,@DATA_INIZIO, @DATA_FINE;
END
CLOSE MY_CURSOR;
DEALLOCATE MY_CURSOR;
/* fine ciclo interno*/
FETCH NEXT FROM MY_CURSOR_max INTO @AMBIENTE_max,@IDCOMPANY_max,@IDEMPLOY_max;
END
CLOSE MY_CURSOR_max;
DEALLOCATE MY_CURSOR_max;
/*fine ciclo principale*/

/*aggiorno tutte le date di fine nulle con data fine= '2999-12-31'*/
UPDATE ZSW_TMP_EMPLOY_1 SET DATA_FINE='29991231' WHERE DATA_FINE IS NULL

 

Is possible in POWER BI  create a similiar procedure?

 

Thanks a lot for your response...

1 REPLY 1
Greg_Deckler
Super User
Super User

So, in Power BI, you use Power Query Editor or Service Content Packs to create tables and then use the Service's scheduled refresh capabilities to update those tables on a regular schedule. Not entirely sure that answers your question or what exactly you are looking to accomplish.



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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